问题描述
我正在创建一个应用程序,当用户按下电源按钮5次时,它需要执行某些操作.
I am creating an app, which needs to do something when the user presses the power button 5 times.
我发现很难在iOS中实现,但我认为这并非没有可能.即使应用在后台运行,如何监听电源键事件?
I figured out that it's difficult to implement in iOS, but I think it's not impossible. How do I listen for power key events, even when the app is running in the background?
有人可以帮我找到解决方法吗?
Can anyone help me to find solution?
推荐答案
您无法直接获取电源按钮事件.但是有些通知可以计数,例如UIApplicationProtectedDataWillBecomeUnavailable
或UIApplicationWillResignActiveNotification
.或仅使用CFNotificationCenter
注册所有低级通知,然后查看是否找到类似com.apple.springboard.lockstate
的内容.
You can't directly get the power button events. But there are notifications which you can count like UIApplicationProtectedDataWillBecomeUnavailable
or UIApplicationWillResignActiveNotification
. Or just register for all low level notifications with CFNotificationCenter
and see if you find something fitting like com.apple.springboard.lockstate
.
这篇关于侦听iOS设备的电源按钮按下情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!