类型 'Notification.Name'(又名 'NSNotification.Name')没有成员 'UIApplication'
Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'UIApplication'
首先它说
'UIApplicationDidEnterBackground' has been renamed to
'UIApplication.didEnterBackgroundNotification'
当我点它时,它说
Type 'Notification.Name' (aka 'NSNotification.Name') has no member
'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)
如果 UIApplicaiton.didEnterBackgroundNotificaiton
不起作用,请尝试 .UIApplicationDidEnterBackground
。
Xcode 11 , swift 5
UIApplication.didBecomeActiveNotification
Xcode 11.4.1, Swift 5
有完全相同的问题。我的问题是我没有在自定义 class
中导入 UIKit
import UIKit
然后我能够实现以下内容:
name: UIApplication.didEnterBackgroundNotification
类似错误'UIApplicationDidChangeStatusBarOrientation' has been renamed to 'UIApplication.didChangeStatusBarOrientationNotification'
解决Swift中的这个错误 5
你应该改变你的称呼方式:
NotificationCenter.default.addObserver(self, selector: #selector(self.configureActivityIndicatorPosition), name: .UIApplicationDidChangeStatusBarOrientation, object: nil)
到
NotificationCenter.default.addObserver(self, selector: #selector(self.configureActivityIndicatorPosition), name: UIApplication.didChangeStatusBarOrientationNotification, object: nil)
首先它说
'UIApplicationDidEnterBackground' has been renamed to 'UIApplication.didEnterBackgroundNotification'
当我点它时,它说
Type 'Notification.Name' (aka 'NSNotification.Name') has no member '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)
如果 UIApplicaiton.didEnterBackgroundNotificaiton
不起作用,请尝试 .UIApplicationDidEnterBackground
。
Xcode 11 , swift 5
UIApplication.didBecomeActiveNotification
Xcode 11.4.1, Swift 5
有完全相同的问题。我的问题是我没有在自定义 class
中导入 UIKitimport UIKit
然后我能够实现以下内容:
name: UIApplication.didEnterBackgroundNotification
类似错误'UIApplicationDidChangeStatusBarOrientation' has been renamed to 'UIApplication.didChangeStatusBarOrientationNotification'
解决Swift中的这个错误 5
你应该改变你的称呼方式:
NotificationCenter.default.addObserver(self, selector: #selector(self.configureActivityIndicatorPosition), name: .UIApplicationDidChangeStatusBarOrientation, object: nil)
到
NotificationCenter.default.addObserver(self, selector: #selector(self.configureActivityIndicatorPosition), name: UIApplication.didChangeStatusBarOrientationNotification, object: nil)