Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 348
Josh Avatar asked Dec 04 '22 00:12

Josh


1 Answers

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

like image 108
keithbhunter Avatar answered Dec 11 '22 12:12

keithbhunter