Unregister from PushKit notifications using unregisterForRemoteNotifications

537 views Asked by At

In our application we're using PushKit to receive VoIP notifications.

When the user logs out we don't want to receive any PushKit notifications. We unregister the device token on our server when the users logs out but if for instance the user doesn't have internet connection when they log out then the request that unregisters the device token will fail (and we allow the user to logout regardless).

That's why we're calling unregisterForRemoteNotifications() when the users logs out (along with unregistering from the server).

However we've noticed that if the request that unregisters the token from the server failed, even if we called unregisterForRemoteNotifications() (and we've confirmed that isRegisteredForRemoteNotifications returns false) we still receive the PushKit notification.

We do check when we receive the notification if the user is logged in, and if not we silently discard the notification.

However, we're concerned that by discarding these notifications we're going to experience the following iOS 13+ crash Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.

What would be the recommended way to tell the system to discard these notifications or to not forward these notifications to our application at all?

Thank you, Cosmin

1

There are 1 answers

0
Jaswant Singh On

Use this

func stopVoIPPush() {
    voipRegistry?.desiredPushTypes = []
    voipRegistry?.delegate = nil
   // voipRegistry = nil
}

Should unregister your PushKit. I used this and it is working.