又有一陣子沒把玩 Admob 了 XD 每次把玩的方式不同,這次看到錯誤訊息:
<Google> Must set the rootViewController property of GADBannerView before calling loadRequest:
以及:
didFailToReceiveAdWithError:Error
其他訊息:
<Google> To get test ads on this device, call: request.testDevices = @[ GAD_SIMULATOR_ID ];
現況與解法:
@interface YourViewController() <GADBannerViewDelegate>
@property (nonatomic, strong) GADBannerView *banner;
@end
@implementation YourViewController
- (GADBannerView *)banner {
if (!_banner) {
// 468*60
_banner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeFullBanner];
_banner.adUnitID = @"ca-app-pub-###############";
}
return _banner;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.banner.frame = CGRectMake(0, self.view.frame.size.height > self.view.frame.size.width ? self.view.frame.size.width - 60 : self.view.frame.size.height - 60, 468, 60 );
self.banner.delegate = self;
[self.view addSubview:self.banner];
// <Google> Must set the rootViewController property of GADBannerView before calling loadRequest:
self.banner.rootViewController = self;
GADRequest* req = [GADRequest request];
// <Google> To get test ads on this device, call: request.testDevices = @[ GAD_SIMULATOR_ID ];
req.testDevices = @[GAD_SIMULATOR_ID];
[self.banner loadRequest:req];
NSLog(@"self.banner: %@", self.banner);
}
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
NSLog(@"adViewDidReceiveAd");
}
- (void)adView:(GADBannerView *)view
didFailToReceiveAdWithError:(GADRequestError *)error
{
NSLog(@"didFailToReceiveAdWithError:%@", error);
}
@end
沒有留言:
張貼留言