如何摧毁 ADMOB 广告?

当我在我的 main.lua 文件中使用下面的代码时,它以我想要的方式显示广告。 但是,当我在“exitScene”场景部分中添加“ads.hide()”(广告仍保留在每个场景中)时,我在终端中收到此错误“attempt to index global 'ads' (a nil value)”,我理解为广告不在模拟器中显示,但当我在我的手机(galaxy s4)上打开应用时,没有任何按钮响应,它只停留在 main.lua 文件/场景上。

local provider = "admob"
local appID = "**********"
local ads = require "ads"

local screenGroup = self.view
local statusText = display.newText( "", 0, 0, native.systemFontBold, 22 )
statusText:setTextColor( 255 )
statusText:setReferencePoint( display.CenterReferencePoint )
statusText.x, statusText.y = display.contentWidth * 0.5, 160

local showAd
local function adListener( event )

    local msg = event.response
    print("Message received from the ads library: ", msg)

    if event.isError then
        statusText:setTextColor( 255, 0, 0 )
        statusText.text = "Error Loading Ad"
        statusText.x = display.contentWidth * 0.5
        local screenGroup = self.view
        showAd( "banner" )
    else

    end
end

if appID then
    ads.init( provider, appID, adListener )
end

local sysModel = system.getInfo("model")
local sysEnv = system.getInfo("environment")

    showAd = function( adType )
    local screenGroup = self.view
    local adX, adY = display.screenOriginX, 400
    statusText.text = ""
    ads.show( adType, { x=adX, y=adY } )
end

if sysEnv == "simulator" then
else
local screenGroup = self.view
    showAd( "banner" )
end

嗨,如何在屏幕更改时关闭或销毁“admob”广告?

点赞
用户1605727
用户1605727

你需要在你创建的每个场景中都调用 广告

在使用 广告插件 的每个 Lua 文件中添加以下行:

local ads = require("ads")
2013-09-13 01:40:07
用户3421174
用户3421174

``` ads.hide( ) ads:removeSelf() ads=nil

你可以将上面的代码插入到任何事件监听器中或其他地方。

2014-03-14 18:35:56
用户2409015
用户2409015

你需要在每个屏幕中调用这个函数。

if ads then
    ads.hide()
end

注:当你生成动态广告时,广告之间会有时间间隔。 因此,如果广告在屏幕上,它会隐藏,否则不会隐藏。 但是,如果你没有检查 if 条件并且移动到下一个场景,广告将会再次加载。

2014-03-20 06:49:56