问题
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