Game Development Community


#1
06/17/2011 (12:37 am)
So, the iOS developer network has a video from WWDC 2010 that shows fairly well how to enable iAd.

developer.apple.com/videos/wwdc/2010/

Based on it I defined a ADBannerView instance. Problem is that the Torque game becomes irresponsive and clicking in the ad banner changes my app's orientation :-)

Code is

In TGBAppDelegate.mm, I added this to the end of this function

- (void)applicationDidFinishLaunching:(UIApplication *)application {

...

ViewController *View = [[ViewController alloc] init];
[window addSubview: View.view];
}


The ViewController class is

ViewController.h


#import <UIKit/UIKit.h>
#import "iAd/ADBannerView.h"

@interface ViewController : UIViewController <ADBannerViewDelegate>
{  
    ADBannerView *adView;
}

ViewController.mm


This defines a ADBannerView instance that is well behaved: it is shown initially hidden and then shown visible when there is an ad in the iAd network to show; it hides the banner again if the iAd network returns no ads to show (like a case of no network connection).

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad 
{
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.hidden = YES;
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape];
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;    
    adView.delegate = self;
    [self.view addSubview:adView];
    [super viewDidLoad];
}

-(void)viewDidUnload
{
    adView.delegate = nil;
    adView = nil;
}

-(void)dealloc
{
    adView.delegate = nil;
    [adView release]; 
    adView = nil; 
    [super dealloc];
}


#pragma mark ADBannerViewDelegate methods

-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    adView.hidden = NO;
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{ 
    adView.hidden = YES;
}
@end

Initial view

www.space-research.org/games/garage_games/126472_1.png

After clicking the banner

www.space-research.org/games/garage_games/126472_2.png

After closing the ad

www.space-research.org/games/garage_games/126472_3.png
#2
06/20/2011 (1:44 pm)
@GG staff

Are there any plans to support iAds in the near future?

The problem here seems to be that iTorque2D does not have a UIViewController (and ADBannerView requires a view controller); so one must be defined and integrated with CAEAGLLayer, that is used to render iTorque; one solution might be to have a dedicated area for iAds only

developer.apple.com/library/ios/#DOCUMENTATION/QuartzCore/Reference/CAEAGLLayer_...
#3
06/20/2011 (10:27 pm)
and why would you need to integrated it with the CAEAGLLayer?
Its not like the context rotates physically so even hooking it in there wouldn't do much.
Instead you would better and also easier to use a view controller which covers only the interactable banner area and overlay that one by pushing it in front
#4
06/21/2011 (12:56 am)
@Mark

Quote:and why would you need to integrated it with the CAEAGLLayer?

I meant using a view controller that manages both CAEAGLLayer and the ADBannerView, making these 2 views "siblings", not ADBannerView integrated with CAEAGLLayer.

Quote:Instead you would better and also easier to use a view controller which covers only the interactable banner area and overlay that one by pushing it in front

Yes, I actually tried that...That is what I do in this modified code version. But the problem is still there, I loose all the CAEAGLLayer input after the ADBannerView shows an ad; therefore the suggestion of the view controller managing both views.

- (void)viewDidLoad 
{
    adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    adView.frame = CGRectMake(0.0f, 0.0f, 320.0, 50.0);
    self.view.frame = CGRectMake(0.0f, 0.0f, 320.0, 50.0);
    adView.hidden = YES;
    adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait]; 
    adView.delegate = self;
    [self.view addSubview:adView];
    self.bannerIsVisible = NO;
    [super viewDidLoad];
}

-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
    adView.hidden = NO;
    [self.view bringSubviewToFront:adView];
}
#5
09/27/2011 (6:55 pm)
I fixed this and posted a resource here

iAd

The problem here was that the ad view was being added as a subview of the default view

[self.view addSubview:adView];

one way to fix this (probably there are others) was to make the default controller view the ADBannerView instance

self.view = adView;