侦听iOS设备的电源按钮按下情况 [英] Listen for iOS device power button presses

查看:136
本文介绍了侦听iOS设备的电源按钮按下情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,当用户按下电源按钮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?

推荐答案

您无法直接获取电源按钮事件.但是有些通知可以计数,例如UIApplicationProtectedDataWillBecomeUnavailableUIApplicationWillResignActiveNotification.或仅使用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设备的电源按钮按下情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆