【问题标题】:Corona Admobs IntegrationCorona Admobs 集成
【发布时间】:2015-01-06 17:22:01
【问题描述】:

-- 我的 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"

-- MY 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 的全局引用

【问题讨论】:

    标签: lua admob coronasdk


    【解决方案1】:

    更改plugins表后尝试如下:

    plugins =
      {
        ["CoronaProvider.ads.admob"] = 
                         { 
                           publisherId = "com.coronalabs",
                    supportedPlatforms = { ["android"] = true }
                 -- supportedPlatforms = { iphone = true, ["iphone-sim"] = true } --for iOS
                         }
      }
    

    继续编码........ :)

    【讨论】:

      【解决方案2】:

      看看这个

      -- ************* 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 很好。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多