- 我的build.settings中的代码
settings =
{
orientation =
{
default = "landscapeRight",
supported = { "landscapeLeft", "landscapeRight" },
},
android =
{
versionCode = "11"
},
androidPermissions =
{
"android.permission.INTERNET",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.READ_PHONE_STATE",
},
build =
{
neverStripDebugInfo = true
},
plugins =
{
-- key is the name passed to Lua's 'require()'
["CoronaProvider.ads.admob"] =
{
-- required
publisherId = "com.coronalabs",
},
},
}
- 我的main.lua中的代码
provider = "admob"
appID = "ca-app-pub-XXX/XXX"
AD_TYPE = "interstitial"
- 我的HomeScreen.lua中的代码
local adsObject = require ("ads")
local toast = require ("toast")
local function adListener( event )
local msg = event.response
toast.new("Event Msg: "..msg, 2000)
print("Message received from the ads library: ", msg)
local statusText = display.newText( "", 0, 0, native.systemFontBold, 22 )
statusText:setTextColor(153, 0, 51)
statusText.x, statusText.y = display.contentWidth * 0.5, 160
if event.isError then
IS_ADD_INIT = false
toast.new("--FALSE--", 2000)
statusText.text = "Error: "..msg;
else
toast.new("--TRUE--", 2000)
IS_ADD_INIT = true
statusText.text = "Success: "..msg;
adsObject.show( AD_TYPE , { x=centerX, y=centerY } )
end
end
function scene:enterScene( event )
local group=self.view
if appID then
adsObject.init( provider, appID, adListener )
else
toast.new("NO APP ID", 2000)
end
end
请帮助。 我无法用上面的代码加载广告。
我的adListener(event)永远不会被调用。 请指正! 我也可以使用我将在main.lua
中定义的adsObject
的全局引用
答案 0 :(得分:0)
在更改plugins
表后尝试如下:
plugins =
{
["CoronaProvider.ads.admob"] =
{
publisherId = "com.coronalabs",
supportedPlatforms = { ["android"] = true }
-- supportedPlatforms = { iphone = true, ["iphone-sim"] = true } --for iOS
}
}
继续编码....................:)
答案 1 :(得分:0)
检查出来
-- ************* ADMOB *********************
-- Hide the status bar
display.setStatusBar( display.HiddenStatusBar )
-- The name of the ad provider.
local adNetwork = "admob"
-- Your application ID
local appID = "a1522213c297e5a"
-- Load Corona 'ads' library
local ads = require "ads"
-- Initialize the 'ads' library with the provider you wish to use.
if appID then
ads.init( adNetwork, appID )
end
-- initial variables
local sysModel = system.getInfo("model")
local sysEnv = system.getInfo("environment")
local bgW, bgH = 320, 480
if appID then
local adX, adY = display.contentCenterX, 0
local halfW = display.contentWidth * 0.5
local font, size = "Helvetica-Bold", 16
if sysEnv == "simulator" then
local warningText2 = display.newText( "Please build for device ", adX, adY, font, size )
local warningText3 = display.newText( "to test this sample code.", adX, adY, font, size )
warningText2:setTextColor( 255, 255, 255)
warningText3:setTextColor( 255, 255, 255)
warningText2:setReferencePoint( display.CenterReferencePoint )
warningText3:setReferencePoint( display.CenterReferencePoint )
warningText2.x, warningText2.y = halfW, 0
warningText3.x, warningText3.y = halfW, 16
else
ads.show( "banner", { x=adX, y=adY} )
end
else
-- If no appId is set, show a message on the screen
local warningText1 = display.newText( "No appID has been set.", 0, 105, font, size )
warningText1:setTextColor( 255, 255, 255)
warningText1:setReferencePoint( display.CenterReferencePoint )
warningText1.x = halfW
end
你的build.settings很好。