I am using Xcode 4.5 with ARC and get the following message using iAd:
WARNING: More than 10 instances of ADBannerView or ADInterstitialView currently exist. This is a misuse of the iAd API, and ad performance will suffer as a result.
I have read this post: Iad WARNING: More than 10 instances of ADBannerView but that code is without ARC it looks, which i have.
My code:
-(AppDelegate *) appdelegate {
return (AppDelegate *) [[UIApplication sharedApplication]delegate];
}
-(void) viewWillAppear:(BOOL)animated {
_UIiAD = [[self appdelegate]UIiAD];
_UIiAD.delegate = self;
adView = [[ADBannerView alloc]initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, 460.0);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject: ADBannerContentSizeIdentifierPortrait];
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
}
- (void) viewWillDisappear:(BOOL)animated {
_UIiAD.delegate = nil;
_UIiAD = nil;
[_UIiAD removeFromSuperview];
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
if(!self.bannerIsVisible) {
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
//banner is invisible now and moved out of the screen
banner.frame = CGRectMake(0.0, 5.0, banner.frame.size.width, banner.frame.size.width);
[UIView commitAnimation];
self.bannerIsVisible = YES;
NSLog(@"bannerViewDidLoadAd is working!");
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
if (self.bannerIsVisible) {
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
//banner is visible and we move it out of the screen due to connection issues
banner.frame = CGRectMake(0.0, -50.0, banner.frame.size.width, banner.frame.size.width);
// [UIView commitAnimation];
self.bannerIsVisible = NO;
NSLog(@"didFailtoReceiveWithError is working");
}
}
-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave {
NSLog(@"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (willLeave && shouldExecuteAction) {
// stop all interaction process in the app. Use this to stop sounds or video so the ad can display properly
// ;
// [sound pause];
}
return shouldExecuteAction;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner {
// resume everything you've stopped
// ;
// ;
}
Because you clear the ad from the ivar first, you are never removing the ad from the superview. Try rewriting as below: