Ads

Hello,

I am having trouble coding ads into my code. Can someone help me? And yes I have tried all the tutorials and none of them worked. I tried updating my app that is already on the app store, but it was rejected due to the lack of the ads. Below I have my build settings and my main.lua. Please Help.

PS: I have my account set up on the admob website, DO I have to use the email associated with my Developer account for my admob account?

Build Setting:

settings = { orientation={ default = "landscape", }, iphone = { plist = { CFBundleShortVersionString = "1.4", UIStatusBarHidden=true, UIApplicationExitsOnSuspend = false, MinimumOSVersion = "4.3", UIAppFonts = { "fonts/ArcadepixPlus.ttf" }, --Facebook Implementation, remove the comment --[[]]-- to use --[[FacebookAppID = "658047860969443", -- replace XXXXXXXXX with your facebook appId CFBundleURLTypes = { { CFBundleURLSchemes = { "fb658047860969443", -- replace XXXXXXXXX with your facebook appId } } }]]-- }, }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", "android.permission.READ\_PHONE\_STATE", }, }, -- admob setup plugins = { ["CoronaProvider.ads.admob"] = { publisherId = "com.coronalabs" }, }, }

main.lua

display.setStatusBar(display.HiddenStatusBar) -- include the Corona "storyboard" module local storyboard = require "storyboard" storyboard.purgeOnSceneChange = true -- to test local textureFilter = "nearest" display.setDefault("minTextureFilter", textureFilter) display.setDefault("magTextureFilter", textureFilter) local preference = require "preference" local sound = preference.getValue("sound") if sound == nil then sound = true preference.save{sound = true} end local adCont = preference.getValue("adCont") if(adCont == nil) then preference.save{adCont=0} end local scores = preference.getValue("scores") if not scores then preference.save{scores = { {char=0, score=0}, }} end config = {} -- global global config['character'] = 1 config['sound'] = sound config['adCont'] = preference.getValue("adCont") -- load menu screen storyboard.gotoScene("menu")

It looks like you’re adding the plugin for admob v1, and not v2. I’m not sure if v1 still works because Google had told everyone to upgrade by August 2014.

See this man page for how to correctly add the v2 plugin.

http://docs.coronalabs.com/plugin/ads-admob-v2/index.html

Then you need to call ads.init() and ads.show() with the correct options. I don’t see any calls to these functions in your main.lua.

@elbowroomapps I tried using this source many time but I just cant seem to get it right. Is there any way that you can show me what the finished code should look like?

I took the iAds example that comes with coronasdk and modified it to use admob instead of iAds. You can download the modified files here:

https://app.box.com/s/489657irqj2c7y9brobz

In the main.lua file, you will see the following line:

local appID = “ca-app-pub-XXXXXXXXXXXXXXXX/XXXXXXXXXX”

You should edit that line and insert the appID for your admob account. Then build the app and install it on an iOS or android device. The app will show buttons that let you show and hide the ads.

I dont want this @elbowroomapps. I already have an app, I just want to have interstitial ads pop up when you die in my app. How do I do that?

I want ads to show up when you die on my app, how do I do that?

@elbowroomgames I did what you said, and yes the interstitial ad shows up, but how do I make it show up on my own app after you die? what code to I type?

If you have correctly included the plugin and run ads.init, then you just need to call ads.show at the point in your code when you want to show the add. The line would look like this:

ads.show( “interstitial”, { x=adX, y=adY, testMode=true } )

@elbowroomgames It worked! But it only showed up once. How do I make it show up multiple times?

It also shows up about three seconds into the game everytime, whether you die or not. How to I make it show up multiple times and on a specific screen when I die? @elbowroomgames

That’s going to depend on your code. You have to put the call to ads.show() at the right spot in your code.Have you tried looking at the sample code? It only shows the ads when you press a button and not before.

Here is part of my c main.lua code

local ads = require( "ads" ) local appID = "ca-app-pub-xxx" local adProvider = "admob" local function adListener( event ) -- The 'event' table includes: -- event.name: string value of "adsRequest" -- event.response: message from the ad provider about the status of this request -- event.phase: string value of "loaded", "shown", or "refresh" -- event.type: string value of "banner" or "interstitial" -- event.isError: false local msg = event.response -- Quick debug message regarding the response from the library print( "Message from the ads library: ", msg ) if ( event.isError ) then print( "Error, no ad received", msg ) else print( "Ah ha! Got one!" ) end end ads.init( "admob", "ca-app-pub-xxx", adListener ) ads.show("interstitial",{x=0, y=0, testMode= true})

My ads.show is at the end of it. Where do I put it to make it show up when you die? And show up more than once?

@elbowroomapps

In your code, how do you know when the character dies? What does your app do when the character dies?

You need to find the spot in your code that handles the character dying, then put the ads.show line there.

@elbowroomapps Should this be in the main.lua or the game.lua

Leave everything in main.lua except for the ads.show. You can just put the ads.show anywhere in game.lua. You have to find the place in the code where the character dies, and then put the ads.show there.

okay thanks! @elbowroomapps

Do I have to do two ads.init() comands if I am using both banner and interstitial ads? @elbowroomapps

I got it to work but there is a delay for the ad to show up after you die. How do I make it show up right when you die?

It’s great you got it working. The ads have to be downloaded over your internet connection, so you might notice the delay if you have a slow connection. I’m not aware of any way to speed it up. 

There have been several threads in these forums on using admob. I would suggest reading through those to see if other people have seen the same problem and what solutions they came up with.

It looks like you’re adding the plugin for admob v1, and not v2. I’m not sure if v1 still works because Google had told everyone to upgrade by August 2014.

See this man page for how to correctly add the v2 plugin.

http://docs.coronalabs.com/plugin/ads-admob-v2/index.html

Then you need to call ads.init() and ads.show() with the correct options. I don’t see any calls to these functions in your main.lua.