Josh Josh - 1 year ago 142
Swift Question

How to detect when iOS app appears in foreground, with Swift?

I need to detect when my app becomes visible? (for example by double tapping the Home button and then tapping on an app that is already in the background)
If possible, I would like to detect that event inside my UIViewController.
I am working with Swift 2.2.

Answer Source

You can use the applicationDidBecomeActive(_:) method of your UIApplicationDelegate. You should read up on the app lifecycle. Your app delegate would then need to inform your view controller in some fashion.

Or you can register your view controller as an observer of the UIApplicationDidBecomeActive notification. Documentation for that can be found here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download