I learned my app does not behave well on multitasking iOS in case a certain ViewController was active when quitting the app. This view controller needs to gather recent information in order to display it. So far initialization code for gathering this information was only placed in viewWillAppear.
Now I've learned viewWillAppear will not be called when the view will appear from background.
Since the world may have changed since the app was send to the background, the view controller needs to reinitialize. I understand I may register for UIApplicationWillEnterForegroundNotification. However, this fires every time the app comes back to the foreground, no matter whether the user is currently navigating to this particular viewController.
Do you have a pattern how to make use of UIApplicationWillEnterForegroundNotification only when the ViewController is active in the sense of "will appear shortly"?
Register for UIApplicationWillEnterForegroundNotification
in viewWillAppear:
, and unregister in viewWillDisappear:
. That way you'll only be notified when the view is actually visible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With