首先,它说
'UIApplicationDidEnterBackground'已重命名为'UIApplication.didEnterBackgroundNotification'
当我说它时,它说
类型'Notification.Name'(又名'NSNotification.Name')没有成员'UIApplication'
func listenForBackgroundNotification() {
observer = NotificationCenter.default.addObserver(forName: Notification.Name.UIApplicationDidEnterBackground, object: nil, queue: OperationQueue.main) { [weak self] _ in
if let weakSelf = self {
if weakSelf.presentedViewController != nil {
weakSelf.dismiss(animated: true, completion: nil)
}
weakSelf.descriptionTextView.resignFirstResponder()
}
}
}
更改
forName: Notification.Name.UIApplicationDidEnterBackground
至
forName: UIApplication.didEnterBackgroundNotification
类型'NSNotification'的错误在swift4.2中没有成员'UIApplication'
NotificationCenter.default.addObserver(self, selector:#selector(handleNotification), name: NSNotification.Name.UIApplicationDidEnterBackground, object: nil)
需要相应更改
NotificationCenter.default.addObserver(self, selector:#selector(handleNotification), name: UIApplication.didEnterBackgroundNotification, object: nil)