Tutorial 23 - Implementing iAds in Codea

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

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

.@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: %@\
", (display ? @"YES" : @"NO"));
    [CodifyAppDelegate delegate].displayingAds = display ? YES : NO;
    [[CodifyAppDelegate delegate] iAdDisplayStatusChanged];
}

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

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

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

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

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.