【发布时间】:2018-06-21 21:45:09
【问题描述】:
嘿嘿,我正在使用下面的代码来检查设备的屏幕是打开还是关闭。我从this SO post 获得此代码。
代码:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), nil, displayStatusChanged, "com.apple.springboard.lockcomplete", nil, CFNotificationSuspensionBehavior.deliverImmediately)
//CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), nil, displayStatusChanged, "com.apple.springboard.lockstate", nil, CFNotificationSuspensionBehavior.deliverImmediately)
return true
}
}//AppDelegate class end here
func displayStatusChanged(center:CFNotificationCenter,observer: UnsafeMutableRawPointer?,name:CFString,object: UnsafeRawPointer?,userInfo:CFDictionary) -> Void {
}
但是我收到了这个错误:
无法转换类型 '(CFNotificationCenter, UnsafeMutableRawPointer?, CFString, UnsafeRawPointer?, CFDictionary) -> Void'到预期的参数类型'CFNotificationCallback!' (又名'ImplicitlyUnwrappedOptional ()>')
有谁知道我在使用displayStatusChanged 函数时做错了什么?任何帮助、建议或链接将不胜感激。
谢谢
【问题讨论】:
-
为什么你的
displayStatusChanged坐在你的课外?
标签: ios swift3 cfnotification