Check if the application resumes with inactive, as it did when you first started it?

I have an NSTimer that I stop when my application resigns, which I restart later when the application becomes active again. I did not understand that applicationWillResignActive will fire when my application starts (pretty obvious). So what happens, my NSTimer does not start correctly (when the application starts). My question is, is there a way to verify that the application resumes from inactive since it starts from it first?

 - (void)applicationWillResignActive:(UIApplication *)application { // STOP CORE TIMER [[[self mapController] coreTimer] invalidate]; [[self mapController] setCoreTimer:nil]; } 

.

 - (void)applicationDidBecomeActive:(UIApplication *)application { // START CORE TIMER [[self mapController] setCoreTimer:[NSTimer scheduledTimerWithTimeInterval:ONE_SECOND target:[self mapController] selector:@selector(timerDisplay:) userInfo:nil repeats:YES]]; } 
+4
source share
1 answer

There is an applicationWillEnterForeground , which seems to work only when the application returns from the background. Just test it will not be called at startup.

Discussion

In iOS 4.0 and later, this method is called part of the transition from the background to the active state. You can use this method to undo many of the changes you made when entering the background. A call to this method is invariably followed by a call to applicationDidBecomeActive: a method that then moves the application from inactive to active.

+4
source

All Articles