Reputation: 4061
I have a timer with a countdown. In recent testing, I've noticed that if I hit the home button and return to the app, the timer is off (fewer seconds have ticked off than should).
I've noticed in testing that ViewDid and ViewWill Appear do not fire when re-opening the app. I know that:
- (void)applicationWillEnterForeground:(UIApplication *)application
Fires, but how do I make it specific to certain part of a viewController that was active?
Upvotes: 0
Views: 726
Reputation: 440
Just for the sake of follow up, as the question was answered above.
I had the exact same problem as Eric and then I implemented Jesse's suggestion about using applicationDidBecomeActive:
on the delegate. I just wanted to make sure how all the different methods were being called, and I found this:
application:didFinishLaunchingWithOptions:
is called at the very start, as expected.viewDidLoad
turn.viewWillAppear:
is called.applicationDidBecomeActive:
is triggered (here I call my reactivateTimer
method which I implemented in the main view controller).reactivateTimer
method is executed.viewDidAppear:
Upvotes: 0
Reputation: 57168
You probably want applicationDidBecomeActive:
and applicationWillResignActive:
, which are sent to your app delegate. There are also notifications posted (e.g. UIApplicationDidBecomeActiveNotification
) you could listen for.
Those are also posted when, e.g., a system alert comes in. If you just want to be told when you're going to the background, try applicationDidEnterBackground:
and applicationWillEnterForeground:
See the Apple Docs on lifecycle for details.
Upvotes: 3