Corona ads doesn't work

Hi, I’ve a problem with Corona ads, I publish my app in play store and then I add the app in Corona ads.

My app in Corona ads has “Active” status but when I put the code in the documentation in my app doesn’t work.

I don’t have any error, my app works well but advertisements don’t be shown.

This is the piece of code that I use for ads.

What can I do?

build.setting

settings =

{
    orientation =
    {
        – Supported values for orientation:
        – portrait, portraitUpsideDown, landscapeLeft, landscapeRight

        default = “landscape”,
        supported = { “landscape”, },
    },
    
    excludeFiles =
    {
        – Include only the necessary icon files on each platform
        android = { “Icon.png”, },
    },
    
    –
    – Android Section
    –
    android =
    {
        usesPermissions =
        {
            “android.permission.INTERNET”,
            “android.permission.ACCESS_COARSE_LOCATION”,
            “android.permission.ACCESS_FINE_LOCATION”,
            “android.permission.ACCESS_NETWORK_STATE”
        },
    },
    –
    --Plugin Section
    –
    plugins =
      {
        [“plugin.google.play.services”] =
        {
          publisherId = “com.coronalabs”,
          supportedPlatforms = { android=true }
        },
        [“shared.android.support.v4”] =
        {
          publisherId = “com.coronalabs”,
          supportedPlatforms = { android=true }
        },
        [“plugin.coronaAds”] =
        {
          publisherId = “com.coronalabs”,
          supportedPlatforms = { android=true }
        },
        [“plugin.chartboost”] =
        {
          publisherId = “com.coronalabs”,
          supportedPlatforms = { android=true }
        },
        [“plugin.adcolony”] =
        {
          publisherId = “com.coronalabs”,
          supportedPlatforms = { android=true }
        }
    }        
}

Page when I want the advertisement:

–Play
–When player click play in main menu this class implements every levels present in the game
local composer = require( “composer” )
local scene = composer.newScene()
local sceneGroup

–Things for Advertisement
local coronaAds = require( “plugin.coronaAds” )
local chartboost = require( “plugin.chartboost” )
– Substitute your own placement IDs when generated
local bannerPlacement = “bottom-banner-320x50”
local interstitialPlacement = “prova”
function prepareAd()
     – Initialize Corona Ads (substitute your own API key when generated)
     coronaAds.init( “a**********************31”, adListener )
      – Initialize the Chartboost plugin with your Corona Ads API key
    chartboost.init( cbListener, { apiKey=“a*****************************31”, appOrientation=“landscape” } )
end
local function adListener( event )
     – Successful initialization of Corona Ads
     if ( event.phase == “init” ) then
       – Show an ad
       --coronaAds.show( bannerPlacement, false )
       coronaAds.show( interstitialPlacement, true )
     end
 end
 –
 – Chartboost
 – Chartboost listener function
 local function cbListener( event )
   if ( event.phase == “init” ) then  – Successful initialization
     chartboost.load( “interstitial” )
   elseif ( event.phase == “loaded” ) then
     if ( event.type == “interstitial” ) then
       chartboost.show( “interstitial” )
     end
   end
 end

– create()
function scene:create( event )
    
end

function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == “will” ) then
        – Code here runs when the scene is still off screen (but is about to come on screen)
    elseif ( phase == “did” ) then
        – Code here runs when the scene is entirely on screen
        prepareAd()
    end
end

function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == “will” ) then
        – Code here runs when the scene is on screen (but is about to go off screen)
    elseif ( phase == “did” ) then
        – Code here runs immediately after the scene goes entirely off screen
    end
end

function scene:destroy( event )

    local sceneGroup = self.view
    – Code here runs prior to the removal of scene’s view
    
end


– Scene event function listeners


scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )


return scene

First, welcome to the forums! Glad you’re here.

Next, it’s really helpful if you post your code using formatting. You can either type:

[lua] ... paste your code here... [/lua]

or click on the blue <> button in the row with Bold, Italics, etc. and paste your code into the window that opens up.

Now to the crux of your problem.  Generally speaking there are two things to using ads (well three in some cases).

  1. You have to initialize the system. This is generally done in main.lua, which is never a composer scene.  These should happen during app start up. They should not be part of your prepareAd() function.

  2. While our documentation shows calling the .show() method in our examples, in reality, you wan to show the ad when you’re ready to show the ad, which is rarely immediately after the initialization completes. You don’t want to call .show() too soon either. In a simple app showing banner ads, it may be okay, but if you’re going to show an interstitial or video ad, you don’t want that to be the first thing people see. For Chartboost, it’s okay to call .load() so it will be ready to show when you’re ready.  Corona Ads doesn’t have a .load() method, so you should hold .show() until you’re ready. And in the chartboost, function you plan to show the ad as soon as it’s loaded again, you want to delay that .show() until later.

  3. Lua is a one pass compiler. When this function:

    function prepareAd()      – Initialize Corona Ads (substitute your own API key when generated)      coronaAds.init( “a**********************31”, adListener )       – Initialize the Chartboost plugin with your Corona Ads API key     chartboost.init( cbListener, { apiKey=“a*****************************31”, appOrientation=“landscape” } ) end

is compiled, both adListener and cbListener are nil. Lua hasn’t assigned addresses to those functions until it gets to them. You have to put the call back functions first:

local function adListener( event ) ... end local cbListener( event ) ... end coronaAds.init( "a\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*31", adListener ) chartboost.init( cbListener, { apiKey="a\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*31", appOrientation="landscape" } )

Now in your scene, call the appropriate .load() and .show() functions as needed.

Rob

First, welcome to the forums! Glad you’re here.

Next, it’s really helpful if you post your code using formatting. You can either type:

[lua] ... paste your code here... [/lua]

or click on the blue <> button in the row with Bold, Italics, etc. and paste your code into the window that opens up.

Now to the crux of your problem.  Generally speaking there are two things to using ads (well three in some cases).

  1. You have to initialize the system. This is generally done in main.lua, which is never a composer scene.  These should happen during app start up. They should not be part of your prepareAd() function.

  2. While our documentation shows calling the .show() method in our examples, in reality, you wan to show the ad when you’re ready to show the ad, which is rarely immediately after the initialization completes. You don’t want to call .show() too soon either. In a simple app showing banner ads, it may be okay, but if you’re going to show an interstitial or video ad, you don’t want that to be the first thing people see. For Chartboost, it’s okay to call .load() so it will be ready to show when you’re ready.  Corona Ads doesn’t have a .load() method, so you should hold .show() until you’re ready. And in the chartboost, function you plan to show the ad as soon as it’s loaded again, you want to delay that .show() until later.

  3. Lua is a one pass compiler. When this function:

    function prepareAd()      – Initialize Corona Ads (substitute your own API key when generated)      coronaAds.init( “a**********************31”, adListener )       – Initialize the Chartboost plugin with your Corona Ads API key     chartboost.init( cbListener, { apiKey=“a*****************************31”, appOrientation=“landscape” } ) end

is compiled, both adListener and cbListener are nil. Lua hasn’t assigned addresses to those functions until it gets to them. You have to put the call back functions first:

local function adListener( event ) ... end local cbListener( event ) ... end coronaAds.init( "a\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*31", adListener ) chartboost.init( cbListener, { apiKey="a\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*31", appOrientation="landscape" } )

Now in your scene, call the appropriate .load() and .show() functions as needed.

Rob