[英]Check Device screen On or Off in iOS
嗨,在這里,我正在使用下面的代碼檢查設備的屏幕是打開還是關閉。 我從這篇SO帖子中獲得了這段代碼。
碼:
@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)->無效'的值轉換為預期參數類型'CFNotificationCallback!' (又名“ ImplicitlyUnwrappedOptional <@convention(c)(可選,可選,可選,可選,可選)->()>”))
有人知道displayStatusChanged
函數在做什么嗎? 任何幫助,建議或鏈接將不勝感激。
謝謝
根據文檔 :
center
參數應該是可選的(即缺少?
), CFString
作為name
,但文檔中顯示CFNotificationName?
CFDictionary
應該是可選的(您缺少?
), 如果您將參數與期望的類型匹配,應該可以解決您的錯誤。
func displayStatusChanged(center: CFNotificationCenter?, observer: UnsafeMutableRawPointer?, name: CFNotificationName?, object: UnsafeRawPointer?, userInfo: CFDictionary?) -> Void {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.