I can’t see anything wrong after a quick read.
Here’s my adnetwork module I use. It has references to other modules, but I hope you’ll be able to make some sense out of it.
One tip: My module temporarily fixes the Chartboost problem of not filling the background of devices with wider and taller displays (iPhone5//iPad) when using letterbox mode (you shouldn’t mess with the width/height settings in config.lua as it will mess up the aspect ratio of the screen which will affect any splash screens you have).
Here’s my module:
-- adnetworks.lua -- created: 2013-07-27 -- -- Ingemar Bergmark -- www.swipeware.com local M = {}; local app = require("appglobals"); local directives = require("directives"); local iap = require("inapp"); local ads = require("ads"); local flags = app.getFlags(); local settings = app.getSettings(); local screen = app.getScreen(); M.isActive = false; -- true if any ad network is showing an ad M.adTapped = false; -- used to prevent new ad from showing when coming back from a tapped ad -- ------------------------------------------------------------------------ -- Vungle -- ------------------------------------------------------------------------ local VUNGLE\_APPID = { Apple = {ID = "xxx"}, Google = {ID = "com.swipeware.freemium.appname"} } local vungleListener = function(event) local eventType = event.type; local isError = event.isError; if (eventType == "adStart") then if (isError) then M.showRevmobPopup(); else audio.pause(flags.chatterChannel); M.isActive = true; flags.cancelAllTouches(); end elseif (eventType == "adEnd") then audio.resume(flags.chatterChannel); M.isActive = false; end end local vungleInit = function() if (directives.STORE ~= "Amazon") then ads.init("vungle", VUNGLE\_APPID[directives.STORE].ID, vungleListener); M.showVungleFullscreen = function() if (not M.isActive) then ads.show("interstitial"); else print("vungle: ad is active") end end end end M.isVungleAvailable = function() if (type(ads.isAdAvailable) == "function") then return ads.isAdAvailable(); end return false; end -- ------------------------------------------------------------------------ -- revmob -- ------------------------------------------------------------------------ local REVMOB\_APPID = { Apple = {ID = "xxx"}, Google = {ID = "yyy"}, Amazon = {ID = "zzz"} } local revmob = nil; -- RebMob handle local revmobFullScreenAd = nil; -- revmob fullscreen ad local revmobPopupAd = nil; -- revmob popup ad local revmobAndroidKey = "Google" -- revmob key for android (must be defined even on iOS builds) local revmobFallback; -- fallback popup/full in case chartboost ad not available if (directives.TARGET == "Android") then revmobAndroidKey = directives.STORE; end local showRevmobAd = function(adType) M.isActive = true; flags.cancelAllTouches(); if (adType == "fullscreen") then revmobFullScreenAd:show(); else -- popup --revmobPopupAd:show(); end end local hideRevmobAd = function() if (revmobFullScreenAd) then M.isActive = false; revmobFullScreenAd:hide(); revmobFullScreenAd = nil; end if (revmobPopupAd) then M.isActive = false; revmobPopupAd:hide(); revmobPopupAd = nil; end end local revmobListener = function(event) local eventType = event.type; local adType = event.ad; if (eventType == "adReceived") then if (flags.canShowAds()) then flags.pauseGame(); showRevmobAd(adType); else hideRevmobAd(); end elseif (eventType == "adClicked") then M.adTapped = true; M.isActive = false; elseif (eventType == "adClosed") then hideRevmobAd(); elseif (eventType == "adNotReceived") then hideRevmobAd(); end end local revmobInit = function() revmob = require("revmob"); local locationHandler = function(event) -- Check for error (user may have turned off Location Services) if (event.errorCode) then print("Location error: "..tostring(event.errorMessage)); else revmob.setUserLocationLatitude(event.latitude); revmob.setUserLocationLongitude(event.longitude); revmob.setUserLocationAccuracy(event.accuracy); end Runtime:removeEventListener("location", locationHandler); end local revmobIDs = {["Android"] = REVMOB\_APPID[revmobAndroidKey].ID, ["iPhone OS"] = REVMOB\_APPID.Apple.ID}; if (flags.TEST\_MODE) then revmob.startSession(revmobIDs); revmob.setTestingMode(revmob.TEST\_WITH\_ADS); revmob.printEnvironmentInformation(revmobIDs); else revmob.startSession(revmobIDs); revmob.printEnvironmentInformation(revmobIDs); end Runtime:addEventListener("location", locationHandler); M.showRevmobFullscreen = function() if (not M.isActive) then revmobFullScreenAd = revmob.createFullscreen(revmobListener); else print("revmob fullscreen: ad is active") end end M.showRevmobPopup = function() if (not M.isActive) then revmobPopupAd = revmob.showPopup(revmobListener); else print("revmob popup: ad is active") end end end -- ------------------------------------------------------------------------ -- ChartBoost -- ------------------------------------------------------------------------ local CHARTBOOST\_APPID = { Apple = {ID = "xxx", SIG = "xxx2"}, Google = {ID = "yyy", SIG = "yyy2"}, Amazon = {ID = "zzz", SIG = "zzz2"} } local chartboost = nil; -- Chartboost handle local overlay1 = nil; -- temporary overlays for chartboost background local overlay2 = nil; local removeOverlays = function() local destroyOverlay = function(object) object:removeEventListener("touch", object); object:removeEventListener("tap", object); object:removeSelf(); end if (overlay1) then destroyOverlay(overlay1) end; if (overlay2) then destroyOverlay(overlay2) end; overlay1 = nil; overlay2 = nil; end local createOverlays = function() local configOverlay = function(object) function object:touch(event) return true; end function object:tap(event) return true; end object:setFillColor(0, 160); object:addEventListener("touch", object); object:addEventListener("tap", object); object:toFront(); transition.from(object, {time=600, alpha=0}); end removeOverlays(); -- remove old overlays in case they are still there if (screen.left \< 0) then overlay1 = display.newRect(screen.left, screen.top, math.abs(screen.left), screen.height); overlay2 = display.newRect(screen.right+screen.left, screen.top, math.abs(screen.left), screen.height); end if (screen.top \< 0) then overlay1 = display.newRect(screen.left, screen.top, screen.width, math.abs(screen.top)); overlay2 = display.newRect(screen.left, screen.bottom+screen.top, screen.width, math.abs(screen.top)); end if (overlay1) then configOverlay(overlay1) end; if (overlay2) then configOverlay(overlay2) end; end local chartboostDelegate = { shouldRequestInterstitial = function(location) return true; end, shouldRequestInterstitialsInFirstSession = function() return true; end, shouldDisplayInterstitial = function(location) if (flags.canShowAds()) then createOverlays(); flags.pauseGame(); flags.cancelAllTouches(); M.isActive = true; return true; else return false; --ignore ad end end, didDismissInterstitial = function(location) timer.performWithDelay(600, removeOverlays); M.isActive = false; return; end, didCloseInterstitial = function(location) M.isActive = false; return; end, didFailToLoadInterstitial = function(location) M.isActive = false; if (revmobFallback == "popup") then M.showRevmobPopup(); else M.showRevmobFullscreen(); end return; end, didClickInterstitial = function(location) M.adTapped = true; M.isActive = false; return; end } local chartboostInit = function() chartboost = require("ChartboostSDK.chartboost"); flags.bundleid = "com.swipeware.freemium.appname"; chartboost.create{ appId = CHARTBOOST\_APPID[directives.STORE].ID, appSignature = CHARTBOOST\_APPID[directives.STORE].SIG, delegate = chartboostDelegate, appVersion = settings.version, appBundle = flags.bundleid }; M.showChartboostFullscreen = function(fallback) revmobFallback = fallback; if (not M.isActive) then chartboost.showInterstitial(); else print("chartboost: ad is active"); end end end M.startChartboostSession = function() chartboost.startSession(); end -- ------------------------------------------------------------------------ M.hideAds = function() hideRevmobAd(); end if (not iap.isBought()) then revmobInit(); vungleInit(); chartboostInit(); end return M;