ios - iAd 卡住游戏场景

标签 ios sprite-kit iad

我正在使用 SpriteKit 开发游戏。我在场景的 View 中显示了 iAds。当触摸广告 View 中的广告时,广告会出现,但是,如果我交叉(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];
            }

        }];



}
}

最佳答案

根据 Apple 的 ADBannerViewDelegate 协议(protocol)引用:

bannerViewActionShouldBegin:willLeaveApplication:

If the willLeave parameter is YES, then your application is moved to the background shortly after this method returns. In this situation, your method implementation does not need to perform additional work. If willLeave is set to NO, then the triggered action will cover your application’s user interface to show the advertising action. Although your application continues to run normally, your implementation of this method should disable activities that require user interaction while the action is executing. For example, a game might pause its game play until the user finishes watching the advertisement.

基本上意味着当您的游戏被插入后台时,游戏将暂停。

当横幅 View 完成它的 Action 时,委托(delegate)有一个更进一步的方法来通知你:

bannerViewActionDidFinish:

Discussion If your delegate paused activities before allowing an action to run, it should resume those activities when this method is called.

看来您可以使用上述委托(delegate)方法来实现您自己的暂停/取消暂停,或者您可以在您的场景中使用 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 ReferenceADBannerViewDelegate Protocol Reference

关于ios - iAd 卡住游戏场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22943829/

相关文章:

ios - 带有 SKSpriteNode 的 UITouch

sprite-kit - SpriteKit - 计算一个物体撞击另一个物体的次数

iphone - 4k 请求后 iAd 填充率为 0

ios - 一起为 UITableView 框架和 contentOffset 设置动画

ios - 在动画中检测图层的交叉点

ios - Google+ 登录与 Google 登录库 [iOS 9 canOpenURL 错误]

iOS IAP - 如何区分 "restoring done, but not purchased before"状态

ios - 点击 userLocation 的标题

ios - 是否可以使用 SpriteKit 创建复杂的平台游戏?

ios - iAd 未加载广告 xcode7