Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tutorial 23 - Implementing iAds in Codea

edited November 2012 in Examples Posts: 563

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.

Comments

  • Posts: 266

    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?

  • Posts: 563

    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.

  • edited November 2012 Posts: 266

    .@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

  • Posts: 266

    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.

  • Posts: 563

    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.

  • Posts: 266

    .@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?

  • Posts: 563

    .@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.

  • edited November 2012 Posts: 266

    .@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

  • Posts: 563

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

  • Posts: 266

    .@Reefwing sent! Thanks for the help

  • Posts: 266

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

  • Posts: 563

    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).

  • Posts: 266

    .@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.

  • Posts: 563

    .@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.

  • Posts: 266

    .@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

  • Posts: 563

    .@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.

  • Posts: 266

    .@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

  • Posts: 563

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

  • Posts: 266

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

  • Posts: 563

    .@veeeralp - I suspect you are actually close to getting it to work. What do the logs show? You need to follow the program flow and identify where the problem lies. Are the:

    NSLog(@"Banner View Ad Shown.");
    NSLog(@"iAds are now working");
    

    statements being called in (void) iAdDisplayStatusChanged?

  • Posts: 266

    .@Reefwing Nope. Those statements are not being called in the console. Maybe the version of the Runtime I have has to do with it? The one I'm using is from August and has been updated a lot since

    This is what I put:

    - (void) iAdDisplayStatusChanged
    {
    
        displayingAds = YES;
        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];
    }
    

    I still don't know why it doesn't work :(

  • Posts: 563

    .@veeeralp - well what you know now is that the method iAdDisplayStatusChanged is not being called, which is why the ads are not being displayed. The next question is why is it not being called?

    Go into aGameCenter_Codea.m and find the showBannerAd method. Add an NSLog message into that, something like what is shown below. If showBannerAd is not being called then the problem is in your Lua code.


    - (void) showBannerAd: (bool)display { NSLog(@"Show Banner Ad Method Called with display set to: %@\n", (display ? @"YES" : @"NO")); [CodifyAppDelegate delegate].displayingAds = display ? YES : NO; [[CodifyAppDelegate delegate] iAdDisplayStatusChanged]; }
  • Posts: 266

    .@Reefwing Nothing shows up in the console pertaining to aGameCenter_Codea.m. I have showBannerAd set to true in 3 different places in my Lua code. I put this in my Lua Code

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

    And the console does show that Ads in Lua are indeed working.

  • edited December 2012 Posts: 563

    .@veeeralp - try this, in the CodifyAppDelegate file, find the method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions and insert the two lines shown below.


    // Initialise Banner Ads _bannerView = [[ADBannerView alloc] init]; _bannerView.delegate = self; displayingAds = YES; // Insert this line and the next. This should [self iAdDisplayStatusChanged]; // load your ads when the app loads. return YES;
  • Posts: 266

    .@Reefwing I tried this and the NSLog statements are now working. However, I can't see my app or the ads. All I have are the NSLog because the screen turns black when testing on my iPhone. Here's what the console shows:

    GNU gdb 6.3.50-20050815 (Apple version gdb-1821) (Sat Jun 30 05:47:55 UTC 2012)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB.  Type "show warranty" for details.
    This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys001
    sharedlibrary apply-load-rules all
    target remote-mobile /tmp/.XcodeGDBRemote-4172-39
    Switching to remote-macosx protocol
    mem 0x1000 0x3fffffff cache
    mem 0x40000000 0xffffffff none
    mem 0x00000000 0x0fff none
    [Switching to process 9219 thread 0x2403]
    [Switching to process 9219 thread 0x2403]
    [Switching to process 9987 thread 0x2703]
    [Switching to process 9219 thread 0x2403]
    2012-12-02 15:50:25.568 Flood Free[14471:907] Banner View Ad Shown.
    2012-12-02 15:50:25.573 Flood Free[14471:907] iAds are now working
    2012-12-02 15:50:25.574 Flood Free[14471:907] Device is in landscape
    2012-12-02 15:50:25.575 Flood Free[14471:907] Application did become active
    warning: Unable to read symbols for /Users/Patel/Library/Developer/Xcode/iOS DeviceSupport/6.0.1 (10A525)/Symbols/System/Library/AccessibilityBundles/AccessibilitySettingsLoader.bundle/AccessibilitySettingsLoader (file not found).
    warning: No copy of AccessibilitySettingsLoader.bundle/AccessibilitySettingsLoader found locally, reading from memory on remote device.  This may slow down the debug session.
    Current language:  auto; currently objective-c++
    (gdb) 
    
  • Posts: 563

    .@veeeralp - that's weird. Rather than continue to chew up forum space I will PM you.

  • Any ideas for when the showBannerAd(bool) seems to not control the ads at all. I can do the code you showed above to have it always on, so I know the framework works, but the function does not seem to work for me.

  • Posts: 563

    Hi @smile4awile - the simulator will only show ads sometimes (which emulates the real world situation), but I assume you have tested this a few times so that is probably not the issue.

    You need to narrow down the problem a bit using some log statements. From what you have written it appears that your issue is not being able to show/hide ads from Lua. First double check that the showBannerAd bool is being set to true in Lua, then check whether that value is being transferred to the Objective C displayingAds bool.

Sign In or Register to comment.