(1): Add the iAd framework
Link Binary With Libraries of Build Phases in the Project Settings, plus iAd. Framework.
(2): drag an ADBannerView in the xib interface.
(3) modify the. h file of ViewController
Add # import <iAd/iAd. h> and add the delegate @ interface ViewController: UIViewController <ADBannerViewDelegate>
Add the following code:
{
IBOutlet ADBannerView * adView;
BOOL bannerIsVisible;
}
@ Property (nonatomic, retain) ADBannerView * adView;
@ Property (nonatomic, assign) BOOL bannerIsVisible;
(4) modify the. m file of ViewController
Add @ synthesize adView under @ implementation ViewController; @ synthesize bannerIsVisible;
Add self. adView. delegate = self in-(void) viewDidLoad;
Add two iad methods:
-(Void) bannerViewDidLoadAd :( ADBannerView *) banner
{
If (! Self. bannerIsVisible)
{
[UIViewbeginAnimations: @ "animateAdBannerOn" context: NULL];
Banner. frame = CGRectOffset (banner. frame, 0,-100 );
[UIViewcommitAnimations];
Self. bannerIsVisible = YES;
}
}
-(Void) bannerView :( ADBannerView *) banner didFailToReceiveAdWithError :( NSError *) error
{
If (self. bannerIsVisible)
{
[UIViewbeginAnimations: @ "animateAdBannerOff" context: NULL];
Banner. frame = CGRectOffset (banner. frame, 0,100 );
[UIViewcommitAnimations];
Self. bannerIsVisible = NO;
}
}