If put together my own ad-rotation system (iAds and inneractive) which looks like the following:
-- require ads functions
local ads = require("ads")
-- set flag telling if app is in test- or life mode
local isTesting = false
-- function to show ads
function showMyAds()
transition.to(adFrame, {time = 140, alpha = 0}) -- fade out placeholder
-- hide any pre-existing ad from screen
ads.hide()
-- show ads with a slight delay
timer.performWithDelay( 200, function() ads.show( "banner", { x = 0, y = 0, interval = 45} ) end)
end
-- hide ads
function hideMyAds()
-- hide any existing ads
ads.hide()
-- set flag
gameData.adVisible = false
end
local function adListener(event)
local msg = event.response
if event.isError then
-- ad error, fade in placeholder for banner
transition.to(adFrame, {time = 140, alpha = 1})
-- set flag
gameData.adVisible = false
-- if iAds does not work, try inneractive
if gameData.adProvider == "iads" then
gameData.adProvider = "inneractive"
ads:setCurrentProvider("inneractive") -- switch to inneractive ad-network
showMyAds()
elseif gameData.adProvider == "inneractive" then
gameData.adProvider = "iads"
ads:setCurrentProvider("iads") -- start over with iAds
showMyAds()
end
else
-- ad retrieved, fade out placeholder for banner
transition.to(adFrame, {time = 140, alpha = 0})
gameData.adVisible = true
end
end
---------------------------------------------------------------------------------
-- INITIALISE ADVERTISEMENTS
---------------------------------------------------------------------------------
local function initialiseAds()
if gameData.appType == "FREE" then
-- initialise all ad networks
ads.init("iads", "XXXXX", adListener)
ads.init("inneractive", "XXXXX", adListener)
-- start with first iAds
gameData.adProvider = "iads"
timer.performWithDelay (200, function() ads:setCurrentProvider("iads") end)
end
end
---------------------------------------------------------------------------------
initialiseAds()
---------------------------------------------------------------------------------
I saved the above code to a file called “adsystem.lua” which is loaded within my main.lua file.
Now to the major crash issue which shows up when displaying inneractive ads. This is driving me nuts and I do not know how to solve this:
When the player starts a game, the function “showMyAds()” is called once the game board has finished drawing. All is fine, the ads show up and rotate depending on availability of ads with iAds and inneractive. Once a game round has ended or the player has quit the game, I clean up the game screen and (amongst other functions) “hideMyAds()” is called to take the ads away from the sreen.
Now comes the ugly part: if the player starts a new game or if he did not quit the game before and starts another game round, the gameboard is re-drawn and “showMyAds()” is called again. It is the exact same procedure as when the player started the game for the first time.
In case of an inneractive ad displayed, the game will crash within 15-30 seconds after the ad has shown up on the screen. I have no clue what is going on but I guess that this is connected to the ads.hide() function which is called once the player has finished/quit his initial game round and where ads were loaded for the first time. The game crash does not occur when displaying iAds, just with inneractive ads. My game does not react on orientation changes so it can not be about that.
To summarize it: first round of ad displayworks fine but after hiding the ads and showing ads again the game crashes.
I would be grateful if someone could help me since this crash is the only thing standing in my way right now and I can not publish the game.
Just a side notice: when showing inneractive ads, the adListener is not triggered for any reason so I can not see if anything went wrong. All works fine with iAds but not event-messages for inneractive ads.
Many thanks.
[import]uid: 101883 topic_id: 36935 reply_id: 336935[/import]