本文介绍了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:

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

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:

似乎您可以使用上述委托方法来实现自己的暂停/取消暂停,或者可以在场景分别使用背景和前景时,在场景中使用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框架参考 ADBannerViewDelegate协议参考

这篇关于iAd冻结了游戏的场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 15:04