Reputation: 21
I can use NSNotification in last version of Xcode 11.1. I can trying to update fields values with a my function refreshFields() after returning to the app from background. My code compiles successfully, but function applicationWillEnterForeground() never calling. Where is the mistake?
@objc func applicationWillEnterForeground(notification: NSNotification) {
refreshFields()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear( animated)
let app = UIApplication.shared
NotificationCenter.default.addObserver(self, selector: #selector(self.applicationWillEnterForeground(notification:)), name: NSExtensionHostWillEnterForeground, object: app)
}
Upvotes: 1
Views: 395
Reputation: 21
I have found a solution. The mistake in name of Notification. It must be: UIApplication.willEnterForegroundNotification
@objc func applicationWillEnterForeground(notification: NSNotification) {
refreshFields()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear( animated)
let app = UIApplication.shared
NotificationCenter.default.addObserver(self, selector: #selector(self.applicationWillEnterForeground(notification:)), name: UIApplication.willEnterForegroundNotification, object: app)
}
Upvotes: 1