Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

appodeal.show() not show
Started by dodi_games Dec 19 2018 09:54 AM

3 replies to this topic
appodeal composer show
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 365 posts
  • Corona SDK

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



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,527 posts
  • Enterprise

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


  • dodi_games likes this

[TOPIC: post.html]
#3

agramonte

[GLOBAL: userInfoPane.html]
agramonte
  • Corona Geek

  • 1,078 posts
  • Corona SDK

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. 


  • dodi_games likes this

[TOPIC: post.html]
#4

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 365 posts
  • Corona SDK

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

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)
  print( "--Start to show interstitial ad--" )
  
  if ( appodeal.isLoaded( "interstitial" ) ) then
    appodeal.show( "interstitial" )
  end

  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?




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: appodeal, composer, show