How to determine the DND mode in an application?

I am creating a medical diagnostic application. Interruptions, while the patient (or doctor) is in the process of using it, violates the purpose of the application and spends a lot of time.

I would like to know how I can detect in the application whether Do Not Disturb is on. (It would also be useful to know if the air plane mode is on). In this way, I could remind the user to enter Settings to enable it.

Even better (much more civilized): is there a way to allow the user to enable DND mode from the application? (Rather, how a user can normalize the volume of a device in an application using MPVolumeView .)


The closest answer that I have found still directs to this page to enable Air Plane mode with a special "URL". But it only works in iOS 5.

+7
source share
2 answers

There is no public API about Do Not Disturb or Airplane Mode. Do not even know the status.

In Air Plane mode, you can check the network status (using Reachability), but it will not be 100% accurate.

Reachability is Apple's sample code , but it has several libraries on GitHub.

+15
source

I found a way to find out if DND is enabled, but it can only be used in certain circumstances ... CallKit will return a specific error code when DND is enabled, for example:

CXCallUpdate *update = [[CXCallUpdate alloc] init]; update.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle]; [(CXProvider *)self.provider reportNewIncomingCallWithUUID:uuid update:update completion:^(NSError *error) { if (error) { NSLog(@"error when reporting imconing: %@", [error localizedDescription]); //The operation couldnt be completed. (com.apple.CallKit.error.incomingcall error 3.) if ([error code] == CXErrorCodeIncomingCallErrorFilteredByDoNotDisturb) { NSLog(@"Disturb mode is on"); } } }]; 
+5
source

Source: https://habr.com/ru/post/1490609/


All Articles