2010-10-26 187 views

回答

2

你不能在模擬器標準的iPhone應用程序運行。這只是Apple向您的應用程序提供的測試廣告。

如果您希望嘗試其他正在構建的iAd設計,則需要從iOS開發人員中心獲取iAd JS框架。這將在模擬器中安裝一個iAd Tester應用程序,該應用程序允許您測試iAd構建。

0

我把這個任務分成3個簡單的步驟。

第1步:

  1. 進口的iAd框架的應用。

  2. 在要顯示廣告的特定控制器中提供#import <iAd/iAd.h>

  3. 提供其委託UIViewController <ADBannerViewDelegate>

  4. 提供一個視圖,以該特定的ViewController。假設我已

@property (weak, nonatomic) IBOutlet UIView *contentView;

步驟2:

//Allocate it in ViewDidLoad method 


- (void)viewDidLoad 

{ 

_bannerView = [[ADBannerView alloc] init]; 

_bannerView.delegate = self; 

[super viewDidLoad]; 

[self.view addSubview:_bannerView]; 

} 

步驟3:

提供我所下面提到其委託方法。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
} else { 
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; 
} 
[self layoutAnimated:duration > 0.0]; 
} 

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
[self layoutAnimated:YES]; 
} 

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error 
{ 
[self layoutAnimated:YES]; 
} 

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave 
{ 

return YES; 
} 

- (void)bannerViewActionDidFinish:(ADBannerView *)banner 
{ 

} 
- (void)layoutAnimated:(BOOL)animated 
{ 
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { 
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
} else { 
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape; 
} 

CGRect contentFrame = self.view.bounds; 
CGRect bannerFrame = _bannerView.frame; 
if (_bannerView.bannerLoaded) { 
contentFrame.size.height -= _bannerView.frame.size.height; 
bannerFrame.origin.y = contentFrame.size.height; 
} else { 
bannerFrame.origin.y = contentFrame.size.height; 
} 

[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{ 
self.contentView.frame = contentFrame; 
[self.contentView layoutIfNeeded]; 
_bannerView.frame = bannerFrame; 
}]; 
}