1

我正在使用带有 ARC 的 Xcode 4.5 并使用 iAd 收到以下消息:

警告:当前存在超过 10 个 ADBannerView 或 ADInterstitialView 实例。这是对 iAd API 的滥用,广告效果将因此受到影响。

我读过这篇文章:Iad 警告:超过 10 个 ADBannerView 实例,但该代码看起来没有 ARC,我有。

我的代码:

-(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
    // [video pause];
    // [sound pause];
}
return shouldExecuteAction;
}

-(void)bannerViewActionDidFinish:(ADBannerView *)banner {
// resume everything you've stopped
// [video resume];
// [audio resume];
}
4

1 回答 1

2

因为您首先从 ivar 中清除广告,所以您永远不会从超级视图中删除广告。尝试重写如下:

- (void) viewWillDisappear:(BOOL)animated {
[_UIiAD removeFromSuperview];
_UIiAD.delegate = nil;
_UIiAD = nil;
}
于 2012-10-19T14:00:57.893 回答