appodeal.show() not show

hi guys in my journey to test ads I’m trying to make an external module to implement ads. Here is the code:

 

--ads.lua local M = {} local appodeal = require( "plugin.appodeal" ) -- Ad listener function M.adsListener = function(event) -- Successful initialization of the Appodeal plugin if ( event.phase == "init" ) then print( "Appodeal event: initialization successful" ) -- An ad loaded successfully elseif ( event.phase == "loaded" ) then print( "Appodeal event: ad loaded successfully" ) appodeal.load("interstitial") appodeal.load("rewardedVideo") -- The ad was displayed/played elseif ( event.phase == "displayed" or event.phase == "playbackBegan" ) then print( "Appodeal event: ad displayed" ) -- The ad was closed/hidden/completed elseif ( event.phase == "hidden" or event.phase == "closed" or event.phase == "playbackEnded" ) then print( "Appodeal event: ad closed/hidden/completed" ) -- The user clicked/tapped an ad elseif ( event.phase == "clicked" ) then print( "Appodeal event: ad clicked/tapped" ) -- The ad failed to load elseif ( event.phase == "failed" ) then print( "Appodeal event: ad failed to load" ) end end M.startAdsPlugin = function(event) appodeal.init( M.adsListener, { appKey = "xxxxxxxxxxxxx", testMode = true, childDirectedTreatment = true, disableAutoCacheForAdTypes = { "interstitial", "rewardedVideo" }, disableWriteExternalPermissionCheck = true, supportedAdTypes = {"interstitial", "rewardedVideo"} } ) end M.showInterstitialAd = function(event) print( "--Start to show interstitial ad--" ) local adTimer = nil local adShowAttempts = 10 local function showAd() if adTimer then timer.cancel( adTimer ) end adShowAttempts = adShowAttempts - 1 if adShowAttempts \<= 0 then return end if not appodeal.isLoaded( "interstitial" ) then adTimer = timer.performWithDelay( 500, showAd ) else appodeal.show( "interstitial" ) end adTimer = timer.performWithDelay( 100, showAd ) end end return M

in main lua I require ads.lua and initialize the appodeal plugin

--main.lua local ads = require( "ads" ) ads.startAdsPlugin()

and in level 1 in the scene:show did phase I call

M.showInterstitialAd() but no ad show

-- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen --test ADS\*\*\*\*\* ads.showInterstitialAd() --ad not show end end

I just want to understand how to show an ad for future use in all scenes

Thanks in advance
DoDi

Please read this tutorial:  http://docs.coronalabs.com/tutorial/basics/ads/index.html

There are several flow issues that I quickly noticed i.e. you only get “loaded” **after** you load an ad. You will never get a “loaded” phases until you call .load(), so it’s impossible to show an interstitial ad. 

However, there are pitfalls to when you load ads. That tutorial discusses all the parts and flow of using advertising.

Rob

Just move:

 appodeal.load("interstitial") appodeal.load("rewardedVideo")

from:

elseif ( event.phase == "loaded" ) then

to:

if ( event.phase == "init" ) then

but I agree with Rob. You should read that document so you understand the flow. 

M.showInterstitialAd = function(event) &nbsp; print( "--Start to show interstitial ad--" ) &nbsp; local adTimer = nil &nbsp; local adShowAttempts = 10 &nbsp; local function showAd() &nbsp;&nbsp;&nbsp; if adTimer then &nbsp; timer.cancel( adTimer ) &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; adShowAttempts = adShowAttempts - 1 &nbsp;&nbsp;&nbsp; if adShowAttempts \<= 0 then &nbsp; return &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; if not appodeal.isLoaded( "interstitial" ) then &nbsp; adTimer = timer.performWithDelay( 500, showAd ) &nbsp;&nbsp;&nbsp; else &nbsp; appodeal.show( "interstitial" ) &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; adTimer = timer.performWithDelay( 100, showAd ) &nbsp; end end

This function do not work for appodeal, maybe for admob, this code is a copy paste from

http://docs.coronalabs.com/tutorial/basics/ads/index.html

and I do not understand why it does not work…

I try this

M.showInterstitialAd = function(event) &nbsp; print( "--Start to show interstitial ad--" ) &nbsp; &nbsp; if ( appodeal.isLoaded( "interstitial" ) ) then &nbsp;&nbsp;&nbsp; appodeal.show( "interstitial" ) &nbsp; end &nbsp; print( "--Ad shown--" ) end

and the ad is shown.

The problem is that, as I do not know how the users will behave with my game, I would like to have control of when an ad is loaded and when it is displayed.

I would like to implement the function that tests if the ad is loaded with the counter. I think it’s a very smart and useful piece of code.

I ask: this piece of code taken from the tutorial was proven in reality or only in theory?

Please read this tutorial:  http://docs.coronalabs.com/tutorial/basics/ads/index.html

There are several flow issues that I quickly noticed i.e. you only get “loaded” **after** you load an ad. You will never get a “loaded” phases until you call .load(), so it’s impossible to show an interstitial ad. 

However, there are pitfalls to when you load ads. That tutorial discusses all the parts and flow of using advertising.

Rob

Just move:

 appodeal.load("interstitial") appodeal.load("rewardedVideo")

from:

elseif ( event.phase == "loaded" ) then

to:

if ( event.phase == "init" ) then

but I agree with Rob. You should read that document so you understand the flow. 

M.showInterstitialAd = function(event) &nbsp; print( "--Start to show interstitial ad--" ) &nbsp; local adTimer = nil &nbsp; local adShowAttempts = 10 &nbsp; local function showAd() &nbsp;&nbsp;&nbsp; if adTimer then &nbsp; timer.cancel( adTimer ) &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; adShowAttempts = adShowAttempts - 1 &nbsp;&nbsp;&nbsp; if adShowAttempts \<= 0 then &nbsp; return &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; if not appodeal.isLoaded( "interstitial" ) then &nbsp; adTimer = timer.performWithDelay( 500, showAd ) &nbsp;&nbsp;&nbsp; else &nbsp; appodeal.show( "interstitial" ) &nbsp;&nbsp;&nbsp; end &nbsp;&nbsp;&nbsp; adTimer = timer.performWithDelay( 100, showAd ) &nbsp; end end

This function do not work for appodeal, maybe for admob, this code is a copy paste from

http://docs.coronalabs.com/tutorial/basics/ads/index.html

and I do not understand why it does not work…

I try this

M.showInterstitialAd = function(event) &nbsp; print( "--Start to show interstitial ad--" ) &nbsp; &nbsp; if ( appodeal.isLoaded( "interstitial" ) ) then &nbsp;&nbsp;&nbsp; appodeal.show( "interstitial" ) &nbsp; end &nbsp; print( "--Ad shown--" ) end

and the ad is shown.

The problem is that, as I do not know how the users will behave with my game, I would like to have control of when an ad is loaded and when it is displayed.

I would like to implement the function that tests if the ad is loaded with the counter. I think it’s a very smart and useful piece of code.

I ask: this piece of code taken from the tutorial was proven in reality or only in theory?