Accepted answer by @Suresh in Swift 3
Set an observer that listens when the application actually enters the background in the ViewController viewDidLoad () method.
NotificationCenter.default.addObserver(self, selector: #selector(myObserverMethod), name:NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
Add the function below to receive notification.
func myObserverMethod(notification : NSNotification) { print("Observer method called")
Brian source share