In my swift app I need to know from what screen my application entered background. Im trying to use NotificationCenter this way:
class MainViewController: UIViewController{
   override func viewDidLoad() {
        super.viewDidLoad()
        let notificationCenter = NotificationCenter.default
        notificationCenter.addObserver(self, selector: #selector(appMovedToBackgroundMain), name: UIApplication.didEnterBackgroundNotification, object: nil)
    }
    @objc func appMovedToBackgroundMain() {
        print("main - App moved to Background!")
    }
}
class InitViewController: UIViewController{
       override func viewDidLoad() {
            super.viewDidLoad()
            let notificationCenter = NotificationCenter.default
            notificationCenter.addObserver(self, selector: #selector(appMovedToBackgroundInit), name: UIApplication.didEnterBackgroundNotification, object: nil)
        }
        @objc func appMovedToBackgroundInit() {
            print("init - App moved to Background!")
        }
    }
and when I'm press Home button at the MainViewController I got in Xcode's console these lines:
init - App moved to Background!
main - App moved to Background!
and I expected only one line there - main - App moved to Background!. How can I reach this?
 
     
     
    