OCT 18, 2010
For more than a year, I’ve worked on the iOS port of iDaft without making a single penny. That’s until Apple announced iAd back in April.
There are multiple success stories about developers who made (and are still making) a fortune with iAd, but that’s another story. Today we just want to quickly get iAds up and running in your app.
Double click your app target and add the iAd framework. If you care about iOS 3 compatibility, make sure it’s weak-linked.

ADBanner views need to be displayed inside a UIViewController since ad content is presented modally. You can add the ADBannerView to your view hierarchy using Interface Builder. However, to stay iOS 3 compatible, you must add the banner programatically after first checking if the symbol exists.
if([ADBannerView respondsToSelector:@selector(class)]) {
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.delegate = self;
[self.view addSubview:adView];
}
If no ad is available (which is the common case), you must hide the banner view (using setAlpha, setHidden, etc). ADBannerViewDelegate offers 2 methods for handling that:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
And 2 other methods for handling user interactions:
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave - (void)bannerViewActionDidFinish:(ADBannerView *)banner
That’s it. By now you should have test advertisements showing up in your app. To learn more about iAd and how it works, you should definitely have a look at Apple’s iAd Programming Guide.
