ADBannerView error (no delegate or delegate does not implement didFailToReceiveAdWithError:)

ADBannerView error (no delegate or delegate does not implement didFailToReceiveAdWithError:)

我的应用在 App Store 上,但没有显示任何广告。因此,在联系 Apple 并没有收到解决方案后,我在控制台中看到了这个错误,而 运行 我的应用程序在模拟器上:

[AppDeveloper] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=1 "Service session terminated." UserInfo=0x7f18e160 {ADInternalErrorCode=1002, NSLocalizedDescription=Service session terminated.}

这就是我的应用不显示任何广告而只在 ADBannerView 所在的位置显示白色 space 的原因吗?

听起来您还没有包含 ADBannerView 的委托方法。我已经评论了您的代码中可能遗漏的部分。

#import <iAd/iAd.h>

@interface ViewController () <ADBannerViewDelegate> // Have you included this?

@end

@implementation ViewController {
    // Your iAd Banner
    ADBannerView *iAdView;
}

-(void)viewDidLoad {
    [super viewDidLoad];

    // Setup iAd view
    iAdView = [[ADBannerView alloc] initWithFrame:CGRectZero];

    iAdView.delegate = self; // And have you done this?

    [iAdView setFrame:CGRectMake(0, 0, iAdView.bounds.size.width, iAdView.bounds.size.height)];
    iAdView.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height - (iAdView.bounds.size.height / 2));
    [self.view addSubview:iAdView];
    iAdView.alpha = 0.0;
}

// And have you included these delegate methods to handle when an ad is received or not?
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    NSLog(@"iAd received ad");
    // display ad
    iAdView.alpha = 1.0;
}

-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    NSLog(@"iAd failed");
    // Hide ad
    iAdView.alpha = 0.0;
}