SpriteKit- the right way to multitask

后端 未结 6 1309
梦毁少年i
梦毁少年i 2020-12-13 01:11

I tried to search everywhere in the code:Explained documentry what it does when going to background, or if it is even paused sometime, but to no avail- can someone direct me

6条回答
  •  情歌与酒
    2020-12-13 01:37

    I was wondering why in the world this seemingly simple solution was causing me crashes on app startup, but it was because I had iAd running. So, a thing to keep in mind: @MassivePenguin's answer works but if you have iAd going you will have to grab the SKView via the subviews or it (obviously) crashes.

    -(SKView*)getSKViewSubview{
        for (UIView* s in self.window.rootViewController.view.subviews) {
            if ([s isKindOfClass:[SKView class]]) {
                return (SKView*)s;
            }
        }
        return nil;
    }
    
    - (void)applicationWillResignActive:(UIApplication *)application {    
        SKView* view = [self getSKViewSubview];
    
        if (view) {
            view.paused = YES;
        }
    
    }
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        SKView* view = [self getSKViewSubview];
    
        if (view) {
            view.paused = NO;
        }
    
    }
    

提交回复
热议问题