问题
I find that sometimes my application (Cocos2d game) beheaves in a "buggy" way after a significant time change. For example:
- case 1: when the application enters the background and, after several minutes, I restart it, I can see the loading image and then the application/game resumes.
- case 2: when the application enters the background and after a significant time change the application sometimes restarts, sometimes not. It is still unclear to me why.
Looking at the AppDelegate methods I found:
// next delta time will be zero
-(void) applicationSignificantTimeChange:(UIApplication *)application
{
[[CCDirector sharedDirector] setNextDeltaTimeZero:YES];
}
I was wondering, as this affects the director and the director affects the animations, is there a link for between this call and case 1 and case 2?
回答1:
This is nothing to do with cocos2D or applicationSignificantTimeChange:
Notably for applicationSignificantTimeChange:
This method is called when the day changes, or if the device's time has been changed in the background for whatever reason (such as changes to time zone).
[Source]
I am assuming the "significant time change" you mention is just when you leave the game for a while (i.e. longer than a few minutes). In this case, it's most likely that you are observing the fact that the OS multitasking handler kills off background processes when the device is running low on memory, causing your app to restart as you describe in case 2.
In the cases where the app hasn't restarted, it's just the case that the OS hasn't killed your process.
来源:https://stackoverflow.com/questions/20327348/understanding-applicationsignificanttimechange