How can I detect DND mode within an app?

后端 未结 2 397
忘了有多久
忘了有多久 2021-01-11 17:56

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

相关标签:
2条回答
  • 2021-01-11 18:51

    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");
                                              }
                                          }
                                      }];
    
    0 讨论(0)
  • 2021-01-11 18:55

    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.

    0 讨论(0)
提交回复
热议问题