我正在开发一个使用SpriteKit的游戏。我在场景的视图中显示了iAds。当广告视图中的广告被触摸时,广告就会出现,然而,如果我交叉(X)/close广告,游戏中的场景就会冻结。当广告出现和消失时,我不会暂停场景或对事件做任何事情。如果我再次触摸广告(现在这是第二次使用冻结场景)并返回到场景,场景解冻,一切都开始正常工作(奇怪的是)。我不确定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];
}
}];
}
}发布于 2014-04-09 10:40:37
根据苹果的ADBannerViewDelegate协议参考:
bannerViewActionShouldBegin:willLeaveApplication:如果willLeave参数为YES,则在此方法返回后不久,您的应用程序将被移到后台。在这种情况下,您的方法实现不需要执行额外的工作。如果willLeave设置为NO,那么触发的操作将覆盖应用程序的用户界面以显示广告操作。尽管您的应用程序可以继续正常运行,但此方法的实现应该禁用在执行操作时需要用户交互的活动。例如,游戏可能会暂停其游戏播放,直到用户看完广告。
基本上,这意味着当你的游戏被推到后台时,游戏将暂停。
代理还有一个方法可以在横幅视图完成其操作时通知您:
bannerViewActionDidFinish:讨论如果您的代理在允许操作运行之前暂停了活动,则在调用此方法时应恢复这些活动。
似乎你可以使用上面的委托方法来实现你自己的暂停/取消暂停,或者当你的应用程序分别移动到后台和前台时,你可以在场景中使用a NSNotification来暂停/取消暂停。
[[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
https://stackoverflow.com/questions/22943829
复制相似问题