iAd冻结了游戏的场景 [英] iAd freezes game's scene

查看:93
本文介绍了iAd冻结了游戏的场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SpriteKit开发游戏.我在现场视图中显示了iAd.当触摸广告"视图中的广告时,该广告就会出现,但是,如果我交叉(X)/关闭该广告,则游戏中的场景将被冻结.当广告出现和消失时,我不会暂停场景或对事件进行任何处理.如果我再次触摸广告(现在是第二次冻结的场景)并返回到该场景,则该场景将解冻,并且一切将按预期的方式开始工作(奇怪的是).我不确定iAd或我的应用中的问题在哪里?

I am developing a game using SpriteKit. I have iAds displayed in a view on the scene. When an ad in the Ad view is touched, the Ad appears, however, if I cross(X)/close the ad the scene in the game is frozen. I do not pause the scene or do anything on the events when the Ad appears and disappears. If I touch the ad again (now this is second time with frozen scene) and return to the scene, the scene un-freezes and everything starts to work as they were suppose to (strangely). I am not sure where is the problem in iAd or my app?

// 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协议参考:

According to Apple's ADBannerViewDelegate Protocol Reference:

bannerViewActionShouldBegin:willLeaveApplication:

如果willLeave参数为YES,则在此方法返回后不久,您的应用程序将移至后台.在这种情况下,您的方法实现无需执行其他工作.如果willLeave设置为NO,则触发的操作将覆盖您应用程序的用户界面以显示广告操作.尽管您的应用程序继续正常运行,但是此方法的实现应禁用在执行操作时需要用户交互的活动.例如,游戏可能会暂停其游戏,直到用户看完广告为止.

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.

从根本上讲,这意味着当您将游戏推入后台时,游戏将暂停.

Basically meaning that as your game is pushed into the background, the game will pause.

委托人还有另一种方法可以在横幅视图完成其操作时通知您:

The delegate has a further method to notify you when the banner view has finished its action:

bannerViewActionDidFinish:

讨论 如果您的委托人在允许执行操作之前暂停了活动,则应在调用此方法时恢复那些活动.

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

似乎您可以使用上述委托方法来实现自己的暂停/取消暂停,或者可以在场景分别使用背景和前景时,在场景中使用NSNotification暂停/取消暂停.

It seems you can either use the above delegate methods to implement your own pause/un-pause or you could use the a NSNotification in your Scene to pause/un-pause when your app moves into the background and foreground respectively.

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(pause)
name:UIApplicationWillResignActiveNotification
object:nil];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(unPause)
name:UIApplicationWillEnterForegroundNotification
object:nil];

来源: iAd框架参考 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆