Ads.isLoaded() becomes false after being loaded successfully ?

Hi. I have an odd behaviour with iOS/Admob (no problem with Android). I am working on an Interstitial module, and it works fine. It goes to one scene, goes to an interstitial and then proceeds to the next.

The problem is the iOS interstitial only displays once ; once it is closed, it then won’t come back when you reShow it. Doesn’t appear to be a connection problem as this happens consistently, e.g. the first load works, subsequent ones do not. (running on iPhone 5C)

Doing some debug printing suggests that once you have gone through the show ad - click to close - hide ad sequence behaviour is different. 

On Android the value Ads.isLoaded(“interstitial”) seems to return true when first loaded and it stays at true. However, on iOS this value subsequently returns false once the interstitial has been closed and doesn’t seem to reload.

Am I supposed to call the preloader again ? I had got the impression that once an interstitial had loaded it stayed loaded ?

Note:May be related to http://forums.coronalabs.com/topic/51128-admob-banner-disappears-after-interstitial-is-closed-ios/?hl=interstitial 

Incidentally, if you have an interstitial Ad that has been closed by the user do you still have to call Ads.hide() ? It doesn’t seem to make any difference to either.

Very confused… has been going from working to not working ??? Anyway, this appears to work reliably. It has a button which is green or red depending on the loading state, pushing the button when green seems to bring up interstitials. I could swear blind the adListener wasn’t working earlier. Ah, well :slight_smile:

display.setStatusBar(display.HiddenStatusBar) -- hide status bar. local Ads = require("ads") -- require advertisement module. local iOSID = "ca-app-pub-8354094658055499/7057436417" -- iOS and Android Admob IDs. local androidID = "ca-app-pub-8354094658055499/2348035218" local isAndroid = system.getInfo("platformName") == "Android" -- running on Android or iOS ? local id = iOSID -- decide which ID to use. if isAndroid then id = androidID end Ads.init("admob",id,function(e) -- initialise the Advert modules. This currently is only called on Android print("[ADMOB] Interstitial adListener",e.phase) if e.phase == "loaded" then print("[ADMOB] Loading complete") end if e.phase == "shown" then -- we cannot use the test in the timer loop because closing the interstitional print("[ADMOB] Forcing interstitial reload") -- does not appear to clear the isLoaded() flag. Ads.hide() -- so re-initialise. Ads.load("interstitial") end end) Ads.load("interstitial") -- load the interstitial local button = display.newCircle(24,24,20) button:setStrokeColor(1,1,0) -- this button is 'show interstitial'. It's green when you can (i.e. loaded) button.strokeWidth = 2 -- and red when you cannot (i.e. not loaded) button:addEventListener("tap",function(e) -- when the button is tapped, show the interstitial if Ads.isLoaded("interstitial") then -- if it has been loaded. Ads.show("interstitial") -- show the advert. end end) timer.performWithDelay(100,function() isLoaded = Ads.isLoaded("interstitial") -- check if the advert is loaded or not. button:setFillColor(1,0,0) -- set button to red or green depending on whether the if isLoaded then button:setFillColor(0,1,0) end -- advert is loaded or not. end,0)

I can’t speak for how Corona’s ads.* API handle this. (I’ve deleoped my own plugin for AdMob on iOS and Android as I’m not very fond of the ads.* API anyway) Natively there’s a difference on how the AdMob SDK for iOS and Android handle interstitials which may result in the behavior your seeing. 

For Android you instantiate an InterstitialAd object which can be re-used between load/show calls. 

On iOS you instantiate a GADInterstitial which is only valid for ONE load/show. There’s a property called .hasBeenUsed to determine if a new interstitial object needs to be created.

I can’t be certain, but it looks like the ads.* API may be trying to use the same interstitial object on iOS after the first load/show which causes the issue you’re seeing.

Very confused… has been going from working to not working ??? Anyway, this appears to work reliably. It has a button which is green or red depending on the loading state, pushing the button when green seems to bring up interstitials. I could swear blind the adListener wasn’t working earlier. Ah, well :slight_smile:

display.setStatusBar(display.HiddenStatusBar) -- hide status bar. local Ads = require("ads") -- require advertisement module. local iOSID = "ca-app-pub-8354094658055499/7057436417" -- iOS and Android Admob IDs. local androidID = "ca-app-pub-8354094658055499/2348035218" local isAndroid = system.getInfo("platformName") == "Android" -- running on Android or iOS ? local id = iOSID -- decide which ID to use. if isAndroid then id = androidID end Ads.init("admob",id,function(e) -- initialise the Advert modules. This currently is only called on Android print("[ADMOB] Interstitial adListener",e.phase) if e.phase == "loaded" then print("[ADMOB] Loading complete") end if e.phase == "shown" then -- we cannot use the test in the timer loop because closing the interstitional print("[ADMOB] Forcing interstitial reload") -- does not appear to clear the isLoaded() flag. Ads.hide() -- so re-initialise. Ads.load("interstitial") end end) Ads.load("interstitial") -- load the interstitial local button = display.newCircle(24,24,20) button:setStrokeColor(1,1,0) -- this button is 'show interstitial'. It's green when you can (i.e. loaded) button.strokeWidth = 2 -- and red when you cannot (i.e. not loaded) button:addEventListener("tap",function(e) -- when the button is tapped, show the interstitial if Ads.isLoaded("interstitial") then -- if it has been loaded. Ads.show("interstitial") -- show the advert. end end) timer.performWithDelay(100,function() isLoaded = Ads.isLoaded("interstitial") -- check if the advert is loaded or not. button:setFillColor(1,0,0) -- set button to red or green depending on whether the if isLoaded then button:setFillColor(0,1,0) end -- advert is loaded or not. end,0)

I can’t speak for how Corona’s ads.* API handle this. (I’ve deleoped my own plugin for AdMob on iOS and Android as I’m not very fond of the ads.* API anyway) Natively there’s a difference on how the AdMob SDK for iOS and Android handle interstitials which may result in the behavior your seeing. 

For Android you instantiate an InterstitialAd object which can be re-used between load/show calls. 

On iOS you instantiate a GADInterstitial which is only valid for ONE load/show. There’s a property called .hasBeenUsed to determine if a new interstitial object needs to be created.

I can’t be certain, but it looks like the ads.* API may be trying to use the same interstitial object on iOS after the first load/show which causes the issue you’re seeing.