ADBannerView错误(没有委托或委托没有实现didFailToReceiveAdWithError :)

时间:2015-02-24 19:46:42

标签: ios runtime-error iad

我的应用程序在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所在的空白区域的原因?

1 个答案:

答案 0 :(得分:0)

听起来你还没有包含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;
}