- (void)createAdBannerView { Class classAdBannerView = NSClassFromString(@"ADBannerView"); if (classAdBannerView != nil) { ... } }这个地方使用NSClassFromString 能够保证代码的后向兼容性,在os 3.x的系统上这个函数不会成功,iAd不会显示,但是程序仍然能够运行.
- (void)viewDidLoad
{
[self createAdBannerView];
}
- (void) viewWillAppear:(BOOL)animated
{
[self refresh];
[self fixupAdView:[UIDevice currentDevice].orientation];
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
[self fixupAdView:toInterfaceOrientation];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_adBannerViewIsVisible)
{
_adBannerViewIsVisible = YES;
[self fixupAdView:[UIDevice currentDevice].orientation];
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (_adBannerViewIsVisible)
{
_adBannerViewIsVisible = NO;
[self fixupAdView:[UIDevice currentDevice].orientation];
}
}
参考: