How to show incoming CallKit window for VoIP push call even if the device "Do not Disturb" is enabled?

901 views Asked by At

We have an application that has CallKit feature. One problem I am facing is that if the user sets Device Do not Disturb mode on, then CallKit incoming notification is not shown if the device is locked. There is a CallKit error that is CXErrorCodeIncomingCallErrorFilteredByDoNotDisturb when the device is in this mode, but I want to still show the notification to the user if a call arrives.

enter image description here

Note: I've found that WhatsApp still shows the incoming CallKit notification even when DND is enabled. Any help/suggestion will be appreciated.

1

There are 1 answers

0
Marco On

If you want to display a notification when you receive a CXErrorCodeIncomingCallErrorFilteredByDoNotDisturb error, you could do the following:

cxProvider.reportNewIncomingCall(
    with: aCallId,
    update: vCallUpdate,
    completion: { error in
        guard let vError = error as? CXErrorCodeIncomingCallError else { return }
        if vError.code == .filteredByDoNotDisturb {
            let content = UNMutableNotificationContent()
            content.title = "Call"
            // ...

            let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)

            UNUserNotificationCenter.current().add(request) { error in
                if let vError = error {
                    print(vError.localizedDescription)
                }
            }
        }
    })

When do-not-disturb is active, WhatsApp doesn't display a notification after receiving an audio call, it only displays notifications for video calls. That's because they use CallKit and PushKit only for audio calls. For video calls they use normal push notifications.