我正在使用SpriteKit开发游戏。我在场景中的视图中显示了iAd。当触摸广告视图中的广告时,广告会出现,但是,如果我跨越(X)/关闭广告,则游戏中的场景将被冻结。当广告出现并消失时,我不会暂停场景或对事件做任何事情。如果我再次触摸广告(现在这是冻结场景的第二次)并返回场景,场景不会冻结,一切都开始工作,就像他们想象的那样(奇怪)。我不确定iAd或我的应用程序中的问题在哪里?
// Method is called when the iAd is loaded.
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
NSLog(@"Banner did load");
[self animateAdBanner];
}
-(void) animateAdBanner{
if(iAdsEnable){
[UIView animateWithDuration:6 delay:8
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
[self.adBanner setAlpha:0.85];
}
completion:^(BOOL finished){
if(finished){
//[self.adBanner setAlpha:0.7];
}
}];
}
}
答案 0 :(得分:1)
根据Apple的ADBannerViewDelegate协议参考:
bannerViewActionShouldBegin:willLeaveApplication:
如果willLeave参数为YES,则此方法返回后不久您的应用程序将移至后台。在这种情况下,您的方法实现不需要执行其他工作。如果willLeave设置为NO,则触发的操作将覆盖应用程序的用户界面以显示广告操作。虽然您的应用程序继续正常运行,但您执行此方法时应禁用在执行操作时需要用户交互的活动。例如,游戏可能暂停其游戏,直到用户完成观看广告。
基本上意味着当你的游戏被推入后台时,游戏会暂停。
代表还有另一种方法可以在横幅视图完成操作时通知您:
bannerViewActionDidFinish:
讨论 如果您的代理在允许某个操作运行之前暂停了活动,那么在调用此方法时它应该恢复这些活动。
您似乎可以使用上面的委托方法来实现自己的暂停/取消暂停,也可以使用场景中的NSNotification暂停/取消暂停,当您的应用分别进入后台和前景时。< / p>
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(pause)
name:UIApplicationWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(unPause)
name:UIApplicationWillEnterForegroundNotification
object:nil];
来源: iAd Framework Reference和ADBannerViewDelegate Protocol Reference