我的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模拟器的bug还是我可以做些什么来解决这个问题?
-(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];
}