在Swift 3中的iOS9和iOS10上检测屏幕锁定或按下主屏幕按钮

保罗·S

通过REAN文在此提供的答案的雨燕2.2伟大的工作,但现在我已经升级到了XCode 8.0斯威夫特3,它不工作了。

我收到以下错误消息:

.../project/AppDelegate.swift:41:108: Cannot convert value of type '(@convention(c) (CFNotificationCenter?, UnsafeMutableRawPointer?, CFString?, UnsafeRawPointer?, CFDictionary?) -> Void)!' to expected argument type 'CFNotificationCallback!'

从这一行:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), nil, LockNotifierCallback.notifierProc(), "com.apple.springboard.lockcomplete", nil, CFNotificationSuspensionBehavior.DeliverImmediately)

在AppDelegate.swift文件中。

有谁知道如何解决这个问题?自从我刚开始学习Swift以来,我们将不胜感激。

技术专家

这可能对您有用。

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
                                    nil,
                                    { (_, observer, name, _, _) in

                                        print("received notification: \(name)")
        },
                                    "com.apple.springboard.lockcomplete" as CFString!,
                                    nil,
                                    .deliverImmediately)

您可以检查此答案以获取更多详细信息。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章