iAd freezes game's scene

流过昼夜 提交于 2019-12-13 06:46:42

问题


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];
            }

        }];



}
}

回答1:


According to Apple's ADBannerViewDelegate Protocol Reference:

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.

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.

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];

Sources: iAd Framework Reference and ADBannerViewDelegate Protocol Reference



来源:https://stackoverflow.com/questions/22943829/iad-freezes-games-scene

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!