Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect DND mode within an app?

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.

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.

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.)


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.

like image 622
JohnK Avatar asked Jul 10 '13 00:07

JohnK


People also ask

Can people see when Do Not Disturb is on?

Can You Tell if Someone Put You On Do Not Disturb? No, you cannot. Your phone will reach that person's voicemail as usual, but they won't hear their ringtone or see a notification on their home screen, so they will be unable to answer.

What is Do Not Disturb mode programmatically in Android?

It has to be granted through the settings menu Settings -> Sound & Notifcation -> Do Not Disturb Access. This is on SDK 23 Marshmallow. setInterruptionFilter is for Lollipop notification priority filter. Use setNotificationPolicy instead.


2 Answers

There's no public API about Do Not Disturb or even Airplane mode. Not even to know the status.

About Airplane mode, you could check the network status (using Reachability), but it wouldn't be 100% accurate.

Reachability is a code sample from Apple, but there are several libraries based on it on GitHub.

like image 165
Marcelo Fabri Avatar answered Oct 12 '22 12:10

Marcelo Fabri


I found a way to know if DND is on, but it may only be used in certain circumstance... The CallKit will return particular error code when DND is on, 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 couldn’t be completed. (com.apple.CallKit.error.incomingcall error 3.)
                                          if ([error code] == CXErrorCodeIncomingCallErrorFilteredByDoNotDisturb) {
                                              NSLog(@"Disturb mode is on");
                                          }
                                      }
                                  }];
like image 24
steven Avatar answered Oct 12 '22 13:10

steven