我放弃了。我一直在尝试整天尝试在切换到我在作曲家中创建的特定场景时,在合理的时间内加载插页式广告来展示广告。我必须做一些内在错误的事情...因为我无法找到关于将插曲广告与插页式广告结合使用的文档,其中我最好的猜测是几乎没有人遇到问题。
无论如何......这是我的源代码。如果您发现任何明显错误,请告诉我......无论哪种方式,感谢阅读。
local composer = require( "composer" )
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called.
-- -----------------------------------------------------------------------------------------------------------------
-- local forward references should go here
centerX = display.contentCenterX
centerY = display.contentCenterY
screenLeft = display.screenOriginX
screenWidth = display.contentWidth - screenLeft * 2
screenRight = screenLeft + screenWidth
screenTop = display.screenOriginY
screenHeight = display.contentHeight - screenTop * 2
screenBottom = screenTop + screenHeight
display.contentWidth = screenWidth
display.contentHeight = screenHeight
display.setStatusBar(display.HiddenStatusBar)
local ads = require( "ads" )
local interstitialAppID = "ca-app-pub-6798972966452738/6428249200"
local adProvider = "admob"
ads.init( adProvider, interstitialAppID, adListener )
local options =
{
effect = "zoomInOutFade",
time = 600,
}
-- -------------------------------------------------------------------------------
local function adListener( event )
if ( event.isError ) then
ads.load("interstitial", {appID = interstitialAppID})
-- attempt to fetch another ad
elseif ( event.phase == "loaded" ) then
ads.show("interstitial", {appID = interstitialAppID})
-- an ad was preloaded
elseif (event.phase ~= "loaded") then
composer.gotoScene("levelSelect", options)
elseif ( event.phase == "shown" ) then
composer.gotoScene("levelSelect", options)
end
end
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == "did" ) then
-- Called when the scene is now on screen.
-- Insert code here to make the scene come alive.
-- Example: start timers, begin animation, play audio, etc.
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen).
-- Insert code here to "pause" the scene.
-- Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == "did" ) then
ads.load("interstitial", {appID = interstitialAppID})
-- Called immediately after scene goes off screen.
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's view ("sceneGroup").
-- Insert code here to clean up the scene.
-- Example: remove display objects, save state, etc.
end
-- -------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -------------------------------------------------------------------------------
return scene
答案 0 :(得分:1)
插页式广告有些确实需要很长时间。
标准流程是在您的活动开始时加载插页式广告,然后在您的应用中的自然断点处加载,检查是否已加载,如果已加载,则显示它。
一旦加载(使用监听器)尝试显示插页式广告,这是一个非常糟糕的主意。它提供了非常糟糕的用户体验,Admob明确表示这违反了他们的政策并且会禁止您的帐户。