Tutorial 23 - Implementing iAds in Codea

I have completed a new tutorial on implementing iAds for your Codea app using the runtime. It is fairly straight forward and includes a new function called showBannerAd(true or false).

You can access the tutorial at http://codeatuts.blogspot.com.au/2012/11/tutorial-23-implementing-iads-with-codea.html

As always, comments welcome.

I keep on getting an error with this last line:

int showBannerAd(struct lua_State *L){
    [CodeaGameCenter showBannerAd:lua_toboolean(L,1)];
    return 0;
}

I think the problem is that I’m not using Game Center for this App. Do I need follow your Game Center tutorial for this bit to work?

Hi @veeeralp - no you don’t need to use Game Center. What is the error? You do need to use the aGameCenter_Codea class though.

.@Reefwing I added everything I need and now i get this error. Here’s a screenshot:
http://d.pr/i/2he1

I already put

showBannerAd(true) 

into the Main.lua

Edit: I went on to replace all the code I had for the files you listed in the tutorial. The only errors I have now are these:

Undefined symbols for architecture i386:
  "_GKPlayerAuthenticationDidChangeNotificationName", referenced from:
      -[aGameCenter_Codea registerForAuthenticationNotification] in aGameCenter_Codea.o
  "_OBJC_CLASS_$_GKAchievement", referenced from:
      objc-class-ref in aGameCenter_Codea.o
  "_OBJC_CLASS_$_GKAchievementViewController", referenced from:
      objc-class-ref in aGameCenter_Codea.o
  "_OBJC_CLASS_$_GKLeaderboardViewController", referenced from:
      objc-class-ref in aGameCenter_Codea.o
  "_OBJC_CLASS_$_GKLocalPlayer", referenced from:
      objc-class-ref in aGameCenter_Codea.o
  "_OBJC_CLASS_$_GKScore", referenced from:
      objc-class-ref in aGameCenter_Codea.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I’m still trying to learn objective c so I’m not entirely sure what they mean.

Hi @veeeralp - you would get the error in the screen shot if you hadn’t added displayingAds and the new call back method iAdDisplayStatusChanged in CodifyAppDelegate.h and CodifyAppDelegate.m.

The second lot of errors are probably because you haven’t linked the Game Center framework called GameKit (which is perfectly reasonable since you aren’t using it). Either delete all the references to the Game Center code (anything which starts with GK requires GameKit e.g. GKLocalPlayer) or it may be easier to just link the framework (instructions here: http://codeatuts.blogspot.com.au/2012/09/tutorial-19-integrating-game-centre.html) like you did for iAds.

My apologies, I should have mentioned this in the tute and will update it.

.@Reefwing Thanks for the tips! I got the simulator working without any errors but I can’t see the iAds in the simulator or on my device. I have the iPhone 5 so maybe that’s the problem. It’s probably getting cut off. Any way to make it always show iAds while testing?

.@veeeralp - iPhone 5 shouldn’t be a problem and it works in the simulator as well. You need to give it a while for the ad to be served up. I assume you have activated iAds for your App in iTunes Connect?

Go into iTunes Connect → iAd Network and you should be able to see your App with the status “Test Ads”.

If that isn’t the problem then you need to give me a bit more to go on.

.@Reefwing The status does say “Test Ads” Are there any changes I need to make to the Code Signing. All I did was move the files in your Dropbox to my Xcode Project. Are there any unique identifiers I need to replace? Can I send you a link to my project via PM? I’ll send it to you once I get home

.@veeeralp - no the unique identifiers are only for the Game Center code. Send it over and i will have a look.

.@Reefwing sent! Thanks for the help

.@Reefwing I sent you a PM again. This time I put the files in Dropbox :slight_smile:

Thanks .@veeeralp - I’ll check it out when I get a chance. I’m travelling all this week.

I had a quick glance at the Lua code and couldn’t see anything obvious - looks like you want to have ads showing all the time. I can’t actually run your app because the ads are linked to your iTunes Connect account. It would help if you could narrow it down a bit (e.g. can you check whether your ads methods are being run in Xcode? Put in some NSLog statements to check).

.@Reefwing Some ad methods are working. Here’s what I got:

- (void) iAdDisplayStatusChanged
{
    if (displayingAds)
    {
        NSLog(@"Banner View Ad Shown.");
        NSLog(@"iAds are now working");
        [_bannerView removeFromSuperview];
        [viewController.view addSubview:_bannerView];
        [viewController.view bringSubviewToFront:_bannerView];
    }
    else
    {
        NSLog(@"Banner View Ad Removed.");
        [_bannerView removeFromSuperview];
    }
    [self layoutAnimated: YES];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    NSLog(@"iAds did load");    
    [self layoutAnimated: YES];
}

In the console, iAds did load does show up, however iAds are now working doesn’t show up. Is there anything else I need to check? Don’t worry about taking too long. I have time because school gets in the way.

.@veeeralp - ok that helps. The good news is that your App is getting served ads. The problem appears to be with the displayingAds boolean. Can you do some logging to check that this is getting set to true by your Lua code? Alternatively, since you are displaying ads all the time just hard code this to true in Xcode. That will at least narrow the problem.

.@Reefwing I did some logging and I can confirm that showBannerAd is getting set to true in the Lua code. Here is what I did:

function setup()
    if showBannerAd then
        print("Ads in Lua are working")
    end

then it printed this in the console
2012-11-28 15:33:52.538 Flood Free[13236:c07] Ads in Lua are working

I have no idea what the problem is now. I utilized all the source code you provided. My paid version got approved and I’m waiting to finish this so I could release both at the same time. Hoping to launch before Christmas

.@veeeralp - you need to check the boolean displayingAds in your Objective C code. As a start just make the first line of the method - (void) iAdDisplayStatusChanged:

displayingAds = YES;

and see whether the ads get displayed. If they do, then the problem is in setting this boolean from Lua. It could be to do with the timing. I set banner ads to true after the splash screen fades while you do it pre-setup.

.@Reefwing I put what you said and put it in a_GameCenter_Codea.m. I get an error and it says "use of undeclared identifier “displayingAds”. I never remember putting this in my code before. This seems to be the problem

.@veeeralp - the method - (void) iAdDisplayStatusChanged is not in the aGameCenter_Codea.m file it is in the CodifyAppDelegate.m file.

.@Reefwing I did what you said and I still doesn’t show the Ads :frowning: I’m beginning to think I should start a new Xcode project and do everything over