Thought I’d share this one.
Makes for easy setup and you also see a placeholder for the ad in the emulator which facilitates testing.
[lua]module(…, package.seeall)
require “ads”
local isDevice = system.getInfo(“environment”) == “device”
local adNetwork = “inmobi”
local appID = “4028cba631d63df101320c65b7e803d3”
local adsTable = {
“banner320x48”,
“banner300x250”,
“banner728x90”,
“banner468x60”,
“banner120x600”
}
local resTable = {
{x=320, y=48},
{x=300, y=250},
{x=728, y=90},
{x=468, y=60},
{x=120, y=600},
}
local dummyAd
local dummyTimer
local adVisible = false
function init()
if isDevice then
ads.init( adNetwork, appID )
end
end
local function stayOnTop()
dummyAd:toFront()
end
function showAd(adIndex, x, y)
if adVisible then return end
if isDevice then
ads.show(adsTable[adIndex], {x=x, y=y, interval=10, testMode=true})
else
dummyAd = display.newRect(x, y, resTable[adIndex].x, resTable[adIndex].y)
dummyTimer = timer.performWithDelay(1000, stayOnTop, 0)
end
adVisible = true
end
function hideAd()
if isDevice then
ads.hide()
else
if dummyTimer then
timer.cancel(dummyTimer)
dummyTimer = nil
end
if dummyAd then
dummyAd:removeSelf()
dummyAd = nil
end
end
adVisible = false
end[/lua]
How to use? Assuming you named the module “inmobi.lua” then
[lua]require “inmobi”
inmobi.init()
– the first param is ad index, in this case 320x48
– the other two params are ad’s position
inmobi.showAd(1, 0, 0)
inmobi.hideAd()[/lua]
Don’t forget to switch the testMode off in code before publishing your app. Also don’t forget to change appId to yours. I won’t be mad if you will, though
[import]uid: 52103 topic_id: 14535 reply_id: 314535[/import]