How To Switch Between Supported Corona Ad Networks?

I think this was a topic somewhere before the new forum, but i can’t find it.

 

Is it possible to switch between the different ad networks in an app? For example, if one network fails to load an ad, I want to try getting an ad from another ad network.

 

If so what are the steps?

Do I have to use ads.init() every time that I want to switch networks? Do I need to use ads.hide() before I do that? Any guidance would be great. Again, if this is possible.

 

Also I am not concerned with people’s opinion’s of the ad networks (iAds,inneractive and inmobi) or trying any of the 3rd party solutions that are floating around. I was just curious how to do this specifically.

Hey, Screaming Leaf, check alexf’s responses in this thread (page 3, and repeat of page 3 in page 4).  Somewhere in the middle, he answers your question:

 

http://forums.coronalabs.com/topic/28563-iads/page-3

http://forums.coronalabs.com/topic/28563-iads/page-4

 

Naomi

There it is!

 

Thanks Naomi!

 

For posterity, this was alexf’s related response:

 

  1. first init all the providers you want to use, all at the same time:

ads.init( “iads”, appID, adListener )
ads.init( “inmobi”, appID, adListener )

 

  1. then switch the current provider as fitting the logic of your code, for example if the iAds network fails to deliver:

– if iads failed
ads:setCurrentProvider(“inmobi”)

Okay so that actually doesn’t seem to work. I am using the latest Daily Build 1056 and testing on an iPad3.

 

iAds seems to work perfectly.

inneractive ads show up, but the adListener event is never called.

inMobi, nothing really happens. I see an inmobi ad request, but the adListener is never called and an ad never shows up.

 

And after a little while the app crashes.

 

This was a test, so all I had was a main.lua file with this:

 

[lua]

local ads = require( “ads” )

 

local function adListener(event)

    print("--------------------AD RESPONSE")

    print("event.response = " … tostring(event.response))

    print("event.provider = " … tostring(event.provider))

    print("event.isError = " … tostring(event.isError))

    print("-------------------------------")

end

 

local adProv = {“iads”,“inneractive”,“inmobi”}

local adIndex = 1

 

ads.init( “iads”, “my iads id”, adListener )

ads.init( “inneractive”, “my inneractive id”, adListener )

ads.init( “inmobi”, “my inmobi id”, adListener )

ads:setCurrentProvider(“iads”)

ads.show( “banner”, { x=0, y=0, interval=60 } )

 

local function switchAds()

    ads.hide()

    adIndex = adIndex + 1

 

    if adIndex > #adProv then

        adIndex = 1

    end

 

    print(">> SWITCH TO "…tostring(adProv[adIndex]))

 

    ads:setCurrentProvider(adProv[adIndex])

 

    if adProv[adIndex] == “inmobi” then

        ads.show( “banner320x48”, { x=0, y=100 } )

    else

        ads.show( “banner”, { x=0, y=100 } )

    end
end

 

timer.performWithDelay( 15000, switchAds,0)

[/lua]

 

I can confirm this.

 

And inneractive is never refreshing (after displaying the first ad, never get another one, no error, no event trigger…)

Yeah, @Screaming Leaf and @ubj3d.android, I filed the bug case #21361.

 

Naomi

 

Edit:  Alexf mentions that they’re in the process of fixing these issues:  http://forums.coronalabs.com/topic/28563-iads/page-4

Hey, Screaming Leaf, check alexf’s responses in this thread (page 3, and repeat of page 3 in page 4).  Somewhere in the middle, he answers your question:

 

http://forums.coronalabs.com/topic/28563-iads/page-3

http://forums.coronalabs.com/topic/28563-iads/page-4

 

Naomi

There it is!

 

Thanks Naomi!

 

For posterity, this was alexf’s related response:

 

  1. first init all the providers you want to use, all at the same time:

ads.init( “iads”, appID, adListener )
ads.init( “inmobi”, appID, adListener )

 

  1. then switch the current provider as fitting the logic of your code, for example if the iAds network fails to deliver:

– if iads failed
ads:setCurrentProvider(“inmobi”)

Okay so that actually doesn’t seem to work. I am using the latest Daily Build 1056 and testing on an iPad3.

 

iAds seems to work perfectly.

inneractive ads show up, but the adListener event is never called.

inMobi, nothing really happens. I see an inmobi ad request, but the adListener is never called and an ad never shows up.

 

And after a little while the app crashes.

 

This was a test, so all I had was a main.lua file with this:

 

[lua]

local ads = require( “ads” )

 

local function adListener(event)

    print("--------------------AD RESPONSE")

    print("event.response = " … tostring(event.response))

    print("event.provider = " … tostring(event.provider))

    print("event.isError = " … tostring(event.isError))

    print("-------------------------------")

end

 

local adProv = {“iads”,“inneractive”,“inmobi”}

local adIndex = 1

 

ads.init( “iads”, “my iads id”, adListener )

ads.init( “inneractive”, “my inneractive id”, adListener )

ads.init( “inmobi”, “my inmobi id”, adListener )

ads:setCurrentProvider(“iads”)

ads.show( “banner”, { x=0, y=0, interval=60 } )

 

local function switchAds()

    ads.hide()

    adIndex = adIndex + 1

 

    if adIndex > #adProv then

        adIndex = 1

    end

 

    print(">> SWITCH TO "…tostring(adProv[adIndex]))

 

    ads:setCurrentProvider(adProv[adIndex])

 

    if adProv[adIndex] == “inmobi” then

        ads.show( “banner320x48”, { x=0, y=100 } )

    else

        ads.show( “banner”, { x=0, y=100 } )

    end
end

 

timer.performWithDelay( 15000, switchAds,0)

[/lua]

 

I can confirm this.

 

And inneractive is never refreshing (after displaying the first ad, never get another one, no error, no event trigger…)

Yeah, @Screaming Leaf and @ubj3d.android, I filed the bug case #21361.

 

Naomi

 

Edit:  Alexf mentions that they’re in the process of fixing these issues:  http://forums.coronalabs.com/topic/28563-iads/page-4