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

旧巷老猫 提交于 2019-12-11 11:15:08

问题


My app is on the App Store and it doesn't show any ad. So, after contacting Apple and receiving no solution, I saw this error in the console while running my app on the simulator:

[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.}

Is that the reason why my app doesn't show any ads and just shows a white space where the ADBannerView is?


回答1:


Sounds like you haven't included the ADBannerView's delegate methods. I've commented the parts you may be missing from your code.

#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;
}


来源:https://stackoverflow.com/questions/28704884/adbannerview-error-no-delegate-or-delegate-does-not-implement-didfailtoreceivea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!