转载自:http://mo7amedfouad.com/2011/08/how-to-integrate-iad-in-your-ios-app/

There is no doubt that the ad industry pushes a lot of companies and individuals to work and grow. the main revenue for Google is AdSense.So why not you get a piece from the pie?.
What is iAD ?

The iAd advertising platform provides developers new opportunities to generate revenue and promote their apps. You add banner or full-screen advertisements to your application’s user interface; Apple sells advertising space and delivers ads to fill these spaces. You earn revenue when users view or interact with ads displayed by your application.

How to integrate iAD in your app ?

The first thing you need to do is to add iAd.framework in your Xcode project which is contained in iOS 4 SDK. Also do not forget to add #import . Developers can choose between two banners: 320×50 px for portrait and 480×32 px for landscape.

For best practices sake:

  • Create and initialize your ADBannerView object in your AppDelegate (SharedAdBannerView).
  • Share the same object a cross your app files.
  • Make sure you remove the ADBannerView when leaving the current view by calling  SharedAdBannerView removeFromSuperview in viewWillAppear delegate
  • You can customize the postion of the iADBannerView in any view but make sure to rest it location when leaving the view using viewWillDisappear

iADAppDelegate.h

1
2
3
4
5
6
7
8
#define SharedAdBannerView ((iADAppDelegate *)[[UIApplication sharedApplication] delegate]).adBanner
 
@interface iADAppDelegate : NSObject <UIApplicationDelegate ,ADBannerViewDelegate> {
 UIWindow *window;
 UITabBarController *tabBarController;
 ADBannerView *adBanner;
}
@property   (nonatomic,retain) ADBannerView *adBanner;

iADAppDelegate.m

1
2
3
4
5
6
7
8
9
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 
adBanner = [[ADBannerView alloc] initWithFrame:CGRectZero];
adBanner.currentContentSizeIdentifier =ADBannerContentSizeIdentifierPortrait;
adBanner.delegate = self;
adBanner.backgroundColor = [UIColor clearColor];
adBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
 return YES;
}

in any controller or view you can position the ad as you want

1
2
3
4
5
6
-(void)viewWillAppear:(BOOL)animated
{
   [SharedAdBannerView removeFromSuperview];
   [SharedAdBannerView  setFrame:CGRectMake(0, 317, 320, 50)];
   [self.view addSubview:SharedAdBannerView];
}

Code strong :)