I want to put ads in my free app. I understand the call button to show ads within the simulator. As I was condensing the code I got stuck as to what was important and what was not, ie; (what code was dependant on the widget library. I only need one button and that is to ask to pay for a app without ads.
Heres the code so far.Thanks
[code]
–==================================================================================================
– INITIAL SETTINGS
– hide the status bar:
display.setStatusBar( display.HiddenStatusBar )
– Below is the ad network that will be used:
local adNetwork = “inneractive”
– Replace nil below with your app ID:
– String; e.g. surrounded by quotes (ex. “abcdefghijklmnop”)
local appID = nil
–==================================================================================================
– Make Banner Ads features available under “ads” namespace
local ads = require “ads”
– Create a text object to display ad status
local statusText = display.newRetinaText( “”, 0, 0, native.systemFontBold, 22 )
statusText:setTextColor( 255 )
statusText:setReferencePoint( display.CenterReferencePoint )
statusText.x, statusText.y = display.contentWidth * 0.5, 160
– Set up ad listener.
local function adListener( event )
– event table includes:
– event.provider (e.g. “inneractive”)
– event.isError (e.g. true/false )
if event.isError then
statusText:setTextColor( 255, 0, 0 )
statusText.text = “Error Loading Ad”
statusText.x = display.contentWidth * 0.5
else
statusText:setTextColor( 0, 255, 0 )
statusText.text = “Successfully Loaded Ad”
statusText.x = display.contentWidth * 0.5
end
end
– initialize ad network:
ads.init( adNetwork, appID, adListener )
– localize a widget function
local widget = require “widget”
widget.setTheme( “theme_ios” )
– initial variables
local sysModel = system.getInfo(“model”)
local sysEnv = system.getInfo(“environment”)
– Shows a specific type of ad
local showAd = function( adType )
local adX, adY = 0, 0
statusText.text = “”
ads.show( adType, { x=adX, y=adY, interval=60, testMode=true } ) – standard interval for “inneractive” is 60 seconds
end
– event listener for widget buttons
local function onButtonRelease( event )
local id = event.target.id
if id == “hideAll” then
ads.hide()
statusText.text = “”
else
showAd( id )
end
end
– if on simulator, make sure onRelease listeners for buttons are reset to nil
if sysEnv == “simulator” then onButtonRelease = nil; end
– create show banner ad button
local bannerButton = widget.newButton{
id = “banner”,
label = “Show Banner Ad”,
labelColor = { default={255}, over={0} },
style = “sheetBlack”,
onRelease = onButtonRelease
}
bannerButton:setReferencePoint( display.CenterReferencePoint )
bannerButton.x = display.contentWidth * 0.5
bannerButton.y = display.contentHeight - 240
– create text ad button
local textButton = widget.newButton{
id = “text”,
label = “Show Text Ad”,
labelColor = { default={0}, over={0} },
style = “sheetGreen”,
onRelease= onButtonRelease
}
textButton:setReferencePoint( display.CenterReferencePoint )
textButton.x = display.contentWidth * 0.5
textButton.y = display.contentHeight - 180
– create fullscreen ad button
local fullScreenButton = widget.newButton{
id = “fullscreen”,
label = “Show Fullscreen Ad”,
labelColor = { default={0}, over={0} },
style = “sheetYellow”,
onRelease= onButtonRelease
}
fullScreenButton:setReferencePoint( display.CenterReferencePoint )
fullScreenButton.x = display.contentWidth * 0.5
fullScreenButton.y = display.contentHeight - 120
– create a hide all ads button
local hideButton = widget.newButton{
id = “hideAll”,
label = “Hide All Ads”,
labelColor = { default={0}, over={0} },
style=“sheetRed”,
onRelease= onButtonRelease
}
hideButton:setReferencePoint( display.CenterReferencePoint )
hideButton.x = display.contentWidth * 0.5
hideButton.y = display.contentHeight - 60
– start with banner ad
showAd( “banner” )
end
[/code] [import]uid: 88495 topic_id: 34715 reply_id: 334715[/import]