Saturday, November 27, 2010

The Simplest Way to Add iAd Banner to Your iPhone Application

It is a bad idea to modify each view controller to add iAd banner. The simplest way to do that is to create a new root view controller and add an AdBannerView and your old root view to it. Do it in your application delegate:


ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.frame=CGRectMake(0, 0, 320, 50);

AdVC* rootVC = [[AdVC alloc] initWithNibName:@"AdVC" bundle:nil];
[window addSubview:rootVC.view];

[rootVC.view addSubview:oldRootVC.view];
[rootVC.view addSubview:adView];
rootVC.view.frame = window.screen.applicationFrame;

oldRootVC.view.frame=CGRectMake(0, 50, 320, 480-50-20);

This will add a banner to all of your views, and it also allows you to easily remove the banner if the user choose to upgrade.

No comments:

Post a Comment