我正在尝试使用以下代码为 UIApplication.didBecomeActiveNotification
添加观察者:
NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: nil) { _ in /* some code */ }
但是 Xcode 说
Type 'UIApplication' has no member 'didBecomeActiveNotification'
尽管它是 officially documented 作为 UIApplication
类常量。我做错了什么? 最佳答案
当您使用 Xcode 10 时,在 build设置 中,如果您将 Swift 语言版本 设置为 Swift 4
,则应编写:
NotificationCenter.default.addObserver(forName: .UIApplicationDidBecomeActive, object: nil, queue: nil) { _ in /* some code */ }
如果它设置为
Swift 4.2
,请改用它:NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: nil) { _ in /* some code */ }
关于ios - 类型 'UIApplication' 没有成员 'didBecomeActiveNotification',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51570341/