我在我的 iPhone 应用程序中集成 iAd 时遇到了问题——横幅广告在消耗时很好(参见http://www.clingmarks.com/iAd1.png和http://www.clingmarks.com/iAd2.png),但是,当我关闭它时,它会留下一个白色的空白屏幕(请参阅http://www.clingmarks.com/iAd3.png)。我不知道为什么。以下是我整合广告的方式:
因为我需要为低版本的 iPhone 操作系统支持其他广告,所以我在应用程序的顶部添加了一个容器视图,其视图控制器是 AdViewController。加载视图后,我以编程方式创建 AdBannerView 并将其作为子视图添加到 AdViewController.view。这是 viewDidLoad 方法中的代码:
Class adClass = (NSClassFromString(@"ADBannerView"));
if (adClass != nil) {
iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];
iAdView.frame = CGRectOffset(iAdView.frame, 0, -50);
iAdView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
iAdView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
iAdView.delegate = self;
iadViewIsVisible = NO;
[self.view addSubview:iAdView];
} else {
// init google adsense
}
以下是委托方法:
enter code here
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
if (!iadViewIsVisible) {
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
iadViewIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (iadViewIsVisible) {
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
iadViewIsVisible = NO;
}
}