共享 iAd 横幅在关闭导航弹出窗口后卸载广告

Shared iAd banner unloads ad after dismissing navigation popover

我看到了其他一些类似的问题,但找不到任何答案...我有一个共享的 iAd 横幅。问题是当我将它加载到带有表 ViewController 的模态呈现的 NavigationController 中时,当我关闭表 ViewController 时,主 ViewController 中的广告横幅丢失了广告,我收到以下内容错误:

ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=7 "The operation couldn’t be completed. Ad was unloaded from this banner" UserInfo=0x5b60e283649 {ADInternalErrorCode=7, NSLocalizedFailureReason=Ad was unloaded from this banner, ADInternalErrorDomain=ADErrorDomain}

视图设置如下: MainViewController --> NavigationController --> TableViewController

在应用程序的另一个位置,我模态地展示了一个 ViewController 共享广告,但我没有遇到这个问题。 (主要ViewController --> ViewController)

这是表ViewController中的代码:

.h

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#import "AppDelegate.h"

@interface TableViewController : UITableViewController <ADBannerViewDelegate>

@property (strong, nonatomic) IBOutlet UITableView *table;
@property (strong, nonatomic) ADBannerView *adView;

@end

.m

-(void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    // Insert Ad Bar
    AppDelegate *appdelegate = (AppDelegate *)[[UIApplication sharedApplication ]delegate];
    _adView = [appdelegate adView];
    _adView.delegate = self;
    self.canDisplayBannerAds = true;

    if (IPAD) {
        [_adView setFrame:CGRectMake(0, self.view.frame.size.height - 65, 320, 65)];
    }
    else {
        [_adView setFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)];
    }
    if (!_adView.bannerLoaded) {
        [_adView setAlpha:0];
    }
    [self.view addSubview:_adView];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
    [UIView commitAnimations];
}

如有任何提示,我们将不胜感激。 谢谢

问题是因为我使用的是:

self.canDisplayBannerAds = true;

以及:

if (IPAD) {
    [_adView setFrame:CGRectMake(0, self.view.frame.size.height - 65, 320, 65)];
}
else {
    [_adView setFrame:CGRectMake(0, self.view.frame.size.height - 50, 320, 50)];
}
if (!_adView.bannerLoaded) {
    [_adView setAlpha:0];
}
[self.view addSubview:_adView];

因此创建了 2 个广告栏实例。