EDIT: I managed to show banner ad, and interstitial ad only once, then I get warning that ad could not load, im checking this now…
ok so im using admob, and the ads are showing as intended using sample project and ur project
yet I am having trouble on my own project…
I am using scenes architecture its very similar to the getting started app
main.lua -> menu.lua -> game.lua
in main I initialize admob, like this:
Summary
local composer = require( "composer" )
-- Hide status bar
display.setStatusBar( display.HiddenStatusBar )
-- Seed the random number generator
math.randomseed( os.time() )
admob = require( "plugin.admob" )
-- Preset the AdMob app ID (replace this with your own for testing/release)
-- This ID must be generated within the AdMob dashboard: https://apps.admob.com/
local appID = "ca-app-pub-5779536996924****"
-- Preset AdMob unit IDs (replace these with your own)
-- These unit IDs must be generated within the AdMob dashboard: https://apps.admob.com/
local bannerUnitID = "ca-app-pub-577953699692***"
local interstitialUnitID = "ca-app-pub-5779536996****"
--ad Listener function
local function adListener( event )
if ( event.phase == "init" ) then -- Successful initialization
-- Load an AdMob banner ad and interstitial ad
print("init")
admob.load( "interstitial", { adUnitId = interstitialUnitID } )
admob.load( "banner", { adUnitId = bannerUnitID } )
-- An ad loaded successfully
elseif ( event.phase == "loaded" ) then
if (event.type == "banner") then
admob.load( "banner", { adUnitId = bannerUnitID } )
print("banner")
elseif (event.type == "interstitial") then
admob.load( "interstitial", { adUnitId = interstitialUnitID } )
print("interstitial")
end
end
end
admob.init( adListener, { appId=appID, testMode=true } )
-- Go to the menu screen
composer.gotoScene( "menu" )
that’s it, I tried using admob.show() inside scene:show function but I will get errors like cannot call init more then once… so right now , without any other code related to ads in my project, I get this :
I/Corona (18635): plugin.admob: 1.2.6 (SDK: 12451000)
I/Corona (18635): init
I/Corona (18635): banner
I/Corona (18635): interstitial
I/Corona (18635): banner
I/Corona (18635): interstitial
I/Corona (18635): banner
I/Corona (18635): interstitial
I/Corona (18635): banner
I/Corona (18635): show
I/Corona (18635): banner
…
…
…
also :
I/Corona (18635): plugin.admob: Test mode active for device ‘E012F5C59D8EF566E1CFCFCABD8B1A49’
I/Corona (18635): interstitial
I/Corona (18635): plugin.admob: Test mode active for device ‘E012F5C59D8EF566E1CFCFCABD8B1A49’
I/Corona (18635): banner
I/Corona (18635): plugin.admob: Test mode active for device ‘E012F5C59D8EF566E1CFCFCABD8B1A49’
I/Corona (18635): banner
I/Corona (18635): plugin.admob: Test mode active for device ‘E012F5C59D8EF566E1CFCFCABD8B1A49’
I/Corona (18635): interstitial
I have a gameloop ofcourse, but im not calling admob anywhere else
I tried doing it without this part:
elseif ( event.phase == "loaded" ) then
if (event.type == "banner") then
admob.load( "banner", { adUnitId = bannerUnitID } )
print("banner")
elseif (event.type == "interstitial") then
admob.load( "interstitial", { adUnitId = interstitialUnitID } )
print("interstitial")
it still gives me other errors like:
I/Corona (13714): ERROR: admob.isLoaded(adType [, options]), admob.init() must be called before calling other API functions
and
I/Corona (13714): WARNING: admob.init(listener, options), init() should only be called once
I have tried also using ur “test” function but and call It inside game.lua, but the init wont recognize the adlistener because its inside another function
basically im confusing, I need a simple solution to make things work right, because the services works well… its all about the coding
by the way, when installing my app (using android “File Manager”) the app crashes and restart 3 times before starting (only at the first time) that didn’t happen before starting to deal with ads