Search code examples
iphoneuiviewviewdidloadviewwillappearviewdidappear

ViewDidAppear Home Button


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?


Solution

  • 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.