我已经实现了iAd代码,但是无论是在模拟器上还是在我的设备上,它都喜欢让iAd在一段时间后消失,即使互联网连接正常。我的实现中有什么地方出了问题吗,或者这只是我所期望的?下面是代码和控制台,其中显示了两者被调用的频率。谢谢!
- (void)viewDidLoad {
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 435); //orginally -50
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
[super viewDidLoad];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"bannerViewDidLoadAd");
if (!self.bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, -25); //orginally 50
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
NSLog(@"bannerViewRecievedError");
if (self.bannerIsVisible)
{
[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, 25); //orginally -50
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)dealloc {
NSLog(@"dealloc");
adView.delegate=nil;
[adView release];
[super dealloc];
}
以下是控制台显示的内容:
2010-12-29 20:04:17.717 app[48943:207] bannerViewRecievedError
2010-12-29 20:04:52.410 app[48943:207] bannerViewRecievedError
2010-12-29 20:05:17.168 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:05:47.166 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:06:16.993 app[48943:207] bannerViewRecievedError
2010-12-29 20:06:46.803 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:07:17.314 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:07:47.140 app[48943:207] bannerViewRecievedError
2010-12-29 20:08:19.899 app[48943:207] bannerViewRecievedError
2010-12-29 20:08:46.978 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:09:17.106 app[48943:207] bannerViewRecievedError
2010-12-29 20:09:46.930 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:10:17.114 app[48943:207] bannerViewDidLoadAd
2010-12-29 20:10:47.609 app[48943:207] bannerViewDidLoadAd
发布于 2010-12-30 04:06:58
不,这里没有问题。苹果公司经常推出新的模拟广告,有时你会遇到错误,以测试你的错误处理能力。该错误可能意味着“没有可用的库存”,这将使您的广告消失。从relevant developer documentation
如果出现错误,横幅视图将调用代理的
:didFailToReceiveAdWithError:方法。发生这种情况时,您的应用程序必须隐藏横幅视图。清单2-3展示了一种你可以实现的方式。它使用与清单2-2相同的属性来跟踪横幅是否可见。如果横幅可见并发生错误,它会将横幅移出屏幕。
即使向您的代理人发送了错误,横幅视图仍会继续尝试下载新广告。这两个委托方法的组合允许您仅在加载广告时显示横幅。
在一个好的错误处理实现上做得不错!
发布于 2010-12-30 04:07:39
它的设计目的是为了确保您可以正确地处理iAd错误。它会随机给你错误和好的测试数据。
https://stackoverflow.com/questions/4559895
复制