I have a Single View Application. When I hit the home button and ‘minimise’ the application I want to be able to execute code when the user reopens it.
For some reason viewDidAppear and viewWillAppear do not execute when I minimise and reopen the application.
Any suggestions?
Thanks in advance
sAdam
You can either execute code in the app delegate in
or register to observe the
UIApplicationDidBecomeActiveNotificationnotification and execute your code in response.There is also the notification
UIApplicationWillEnterForegroundNotificationand the method- (void)applicationWillEnterForeground:(UIApplication *)applicationin the app delegate.To hook up notifications add this at an appropriate point
Define a the corresponding method
Then don’t forget to remove yourself an observer at an appropriate point
Discussion
You most likely only want your viewController to respond to events whilst it is the currently active view controller so a good place to register for the notifications would be
viewDidLoadand then a good place to remove yourself as an observer would beviewDidUnloadIf you are wanting to run the same logic that occurs in your
viewDidAppear:method then abstract it into another method and haveviewDidAppear:and the method that responds to the notification call this new method.