我可以在 Xcode 11.1 的最新版本中使用 NSNotification。从后台返回应用程序后,我可以尝试使用我的函数refreshFields()更新字段值。我的代码编译成功,但函数applicationWillEnterForeground()从不调用。错误在哪里?
@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)
}