Friday, 12 October 2012

Implementing iAd in iPhone/iPad/iPod Touch Application

Implementing iAds in your iPhone/iPad Application is really very simple.

1. First add "iAd.framework" Framework from Targets -> Build Phases -> Link Binary With Libraries.

2. In ViewController.h #import  <iAd/ADBannerView.h>
3. Take ADBannerViewDelegate.

4. Now take a ADBannerView in ViewController.xib.
5. Set IBOutlet to ADBannerView (as iADBannerView here).
6. Set delegate of ADBannerView to File Owner(self).

7. In ViewController.m set iADBannerView as Hidden in viewDidLoad method. Which will hide the ADBannerView while loading controller screen.
8. Now add delegate methods of ADBannerView mentioned below:

- (void)bannerViewDidLoadAd:(ADBannerView *)banner;

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error;

9. In bannerViewDidLoadAd method unhide the ADBannerView. As method name specifies this method is executed when ADBannerView loads.

10. If there is any issue in loading ADBannerView the bannerView: didFailToReceiveAdWithError is executed.

11. Now when top tap on ADBannerView it will show you a "Test Advertisement" screen as shown in below snapshot. This means you are all done, and ready to go.

You can download sample code from here: iAdDemo

No comments:

Post a Comment