我在创建一个将在模拟器和设备上显示的admob广告时遇到问题。目前我只会在模拟器上显示。我在这里得到一则广告:PUBLISHER TEST AD。
我已经搜索了一段时间,但无法找到解决方案
为什么它也不会在设备上显示?
- (void)viewDidLoad
{
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-50, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
self.bannerView.adUnitID = myAdUnitID;
self.bannerView.delegate = self;
[self.bannerView setRootViewController:self];
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[self createRequest]];
[self.navigationController.tabBarController.tabBar setHidden:YES];
}
-(GADRequest *)createRequest {
GADRequest *request = [GADRequest request];
request.testDevices = [NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
return request;
}
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(@"Ad Received");
[UIView animateWithDuration:1.0 animations:^{
adView.frame = CGRectMake(0.0, self.view.frame.size.height-50, adView.frame.size.width, adView.frame.size.height);
}];
}
-(void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"error due to: %@", [error localizedFailureReason]);
}
答案 0 :(得分:1)
Admobs ad only shows on the simulator
因为您在此行代码中添加了GAD_SIMULATOR_ID
,因此它仅在模拟器上显示测试广告。
[NSArray arrayWithObjects:GAD_SIMULATOR_ID, nil];
所以我的意见是你可以在设备上进行测试,就像你在这个数组中添加device id
一样。每次打开这个应用程序时,这将显示测试添加,如果在{{{ 1}}这会显示广告并开始在Google Admob
帐户上显示展示次数。