【发布时间】:2015-04-25 10:32:29
【问题描述】:
我的 iAd/AdMob 中介适用于所有 iOS 7 模拟器和设备。但是,iOS 8 didFailToReceiveAdWithError 方法不适用于任何模拟器,但它适用于 iOS 8 设备。问题是我没有要测试的 iPhone 6/6+ 设备。所以我指望 iOS 8 模拟器。
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView beginAnimations:nil context:NULL];
iAd.frame=CGRectOffset (iAd.frame 0, -667);
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
iAd.frame=CGRectOffset (iAd.frame 0, 0);
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:NULL];
iAd.frame=CGRectOffset (iAd.frame 0, -740);
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
AdMob.frame=CGRectOffset (iAd.frame 0, -667);
[UIView commitAnimations];
}
我什至不知道 didFailToReceive 坐标是否正确,因为我无法测试。我不明白为什么只为 iOS 8 模拟器调用 didFailToReceiveAdWithError ?这是 iOS 8 模拟器的错误还是我可以做些什么来解决这个问题?
// 忽略^^
-(AppDelegate *)appdelegate{
return (AppDelegate *) [[UIApplication sharedApplication] delegate];
}
-(void)viewWillAppear:(BOOL)animated{
//iAD
_iAdView= [[self appdelegate] iAdView];
_iAdView.delegate=self;
screenBounds = [[UIScreen mainScreen] bounds];
[_iAdView setFrame:CGRectMake(0, 0, _iAdView.bounds.size.width, _iAdView.bounds.size.height)];
_iAdView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.origin.y + (_iAdView.bounds.size.height / 2));
[self.view addSubview:_iAdView];
//ADMOB
_adMobView= [[self appdelegate] adMobView];
_adMobView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
_adMobView.adUnitID = @"My-Unit-ID";
_adMobView.rootViewController = self;
GADRequest *request =[GADRequest request];
request.testDevices = @[ @"Test-Number" ];
[_adMobView loadRequest:request];
[_adMobView setFrame:CGRectMake(0, 0, _adMobView.bounds.size.width, _adMobView.bounds.size.height)];
_adMobView.center = CGPointMake(screenBounds.size.width / 2, screenBounds.size.height - (_adMobView.bounds.size.height / 2));
[self.view addSubview:_adMobView];
}
-(void)viewWillDisappear:(BOOL)animated{ //Whether I remove this or not, nothing changes
//iAD
_iAdView.delegate = nil;
_iAdView=nil;
_iAdView.alpha=0.0;
//ADMOB
_adMobView.delegate=nil;
_adMobView=nil;
_adMobView.alpha=0.0;
}
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
NSLog(@"iAd received");
_iAdView.alpha=1.0;
_adMobView.alpha = 0.0;
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
NSLog(@"iAd failed, AdMob received");
_iAdView.alpha=0.0;
_adMobView.alpha=1.0;
[UIView commitAnimations];
}
【问题讨论】:
-
以上坐标是 iPhone 6 的。-667 是 iPhone 6 屏幕的顶部。 0 位于不可见的底部下方。我假设 -774 将在 -667 的顶部上方不可见,并且我假设当 iAd 失败并且 AdMob 加载时,它将加载到与首次使用 -667 调用时加载的 iAd 相同的位置。但我不知道,因为我无法测试 iOS 8 模拟器。我确实放了 NSLog 消息,当 iAd 失败并且应该出现 Admob 时,会出现 NSLog 消息但横幅永远不会出现。我移动了坐标,但横幅仍然只出现在 iOS 8 模拟器上。
标签: xcode ios8 admob ios-simulator iad