iAds: bannerViewDidLoadAd no longer called after first didFailToReceiveAdWithError
I'm testing iAds in XCode 4.
Everything works fine, until the first time a bannerView:didFailToReceiveAdWithError:
is received, which I react to by sliding the banner off the screen.
//move t开发者_JAVA技巧he ad back off the screen if an error occurs
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (self.bannerIsInScreenBounds)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// move the banner view off the screen.
banner.frame = CGRectOffset(banner.frame, 320, 0);
[UIView commitAnimations];
}
}
After that, no more bannerViewDidLoadAd:
messages are sent to the ADBannerViewDelegate. I'm logging that method right at the top, it's not being called any more.
I'm not releasing the banner or anything, and the ADBannerViewDelegate class is still there and doing other stuff.
What could be wrong?
Thanks.
Why do you expect it load adverts after an error has happened - I think this is the correct behavior.
Looking at the comments it show that the error is "The operation couldn’t be completed. Ad inventory unavailable".
How do you expect it to give you adverts if it can't find any adverts to give ;)
OK, not an ideal solution but here's what I ended up doing.
Whenever I get a didFailToReceiveAdWithError, I wait 10 seconds (to avoid spamming with failures) then recreate the banner.
-(void)replaceAdView {
UIView *adViewSuperview = [adView superview];
[adView removeFromSuperview];
[adView release];
//starting off the screen again
adView = [[NSClassFromString(@"ADBannerView") alloc] initWithFrame:CGRectMake(320, 382, 320, 50)];
adView.delegate = self;
if (adViewSuperview) {
[adViewSuperview addSubview:adView];
}
self.bannerIsInScreenBounds = NO;
}
As my comment at how to implement AdBannerview and ADBannerview delegate, running iphone app in ipad simulator I got didFailToReceiveAdWithError
immediately on setting the ADBannerView delegate, and never another delegate call. Running it on the iphone simulator (or changing the app target to universal) the delegate only got called after adding ADBannerView as a subview, and then delegate calls every 30 secs after that.
精彩评论