Using applicationDidBecomeActive makes app lag and slow after awakening it

断了今生、忘了曾经 提交于 2019-12-11 18:25:40

问题


NOTE: This only happens when I use cocos2d and spritebuilder. I tried the same exact code with just a single view app which worked fine.

When using applicationDidBecomeActive to send an NSLog, the app becomes laggy and slow upon being reopened. This is an extremely simple app so it does not have to do with intensive graphics or processes.

MainScene.m

#import "MainScene.h"

@implementation MainScene

int score;

-(void)digButton {
    score++;
    scoreLabel.string = [NSString stringWithFormat:@"%i", score];
}
@end

then this is the method in appdelegate.

-(void)applicationDidBecomeActive:(UIApplication *)application
{
    NSLog(@"hi");
}

Does this method not work correctly with cocos2d or something?


回答1:


Make sure to call the super implementation o CCAppDelegate methods:

-(void)applicationDidBecomeActive:(UIApplication *)application
{
    NSLog(@"hi");
    [super applicationDidBecomeActive:application];
}

Without that the default CCAppDelegate implementation won't run, which resumes the director:

-(void) applicationDidBecomeActive:(UIApplication *)application
{
    [[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
    if( [navController_ visibleViewController] == [CCDirector sharedDirector] )
        [[CCDirector sharedDirector] resume];
}


来源:https://stackoverflow.com/questions/24946665/using-applicationdidbecomeactive-makes-app-lag-and-slow-after-awakening-it

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