如何在应用程序中检测DND模式?
我正在构建医疗诊断应用程序。当患者(或医生)在使用过程中发生中断时,会中断应用程序的用途并浪费大量时间。
I'm building a medical diagnostic app. Interruptions while a patient (or doctor) is in the midst of using it would disrupt the purpose of the app and waste a lot of time.
我想知道如何在应用程序中检测请勿打扰模式是否已打开/关闭。 (最好知道Air Plane Mode是否处于开/关状态。)这样,我可以提醒用户进入设置以将其打开。
I would like to know how I can detect within an app whether Do Not Disturb mode is switched on/off. (It would also be good to know whether Air Plane Mode is on/off.) That way I could remind the user to go into Settings to turn it on.
甚至更好(更文明):有什么方法可以允许用户从应用程序内的中打开DND模式? (就像用户可以使用 MPVolumeView 。)
Even better (much more civilized): is there any way I could allow the user to turn on DND mode from within the app? (Rather like the user can normalize the device volume within an app using MPVolumeView.)
最接近的我已经找到的答案指向此页面,其中带有特殊的 URL以启用飞机模式。但是它仅适用于iOS 5 。
The closest answer I've yet found directs to this page on turning on Air Plane mode with a special 'URL.' But it only works in iOS 5.
没有关于请勿打扰甚至飞机模式的公共API。甚至不知道状态。
There's no public API about Do Not Disturb or even Airplane mode. Not even to know the status.
关于飞行模式,您可以检查网络状态(使用可达性),但是它不是100%准确的。
About Airplane mode, you could check the network status (using Reachability), but it wouldn't be 100% accurate.
Reachability是苹果公司的代码示例,但是在GitHub上有一些基于它的库。
Reachability is a code sample from Apple, but there are several libraries based on it on GitHub.