twilio / voice-quickstart-ios

Twilio Voice Quickstart for iOS with Swift
MIT License
182 stars 96 forks source link

Unregistering device after user uninstall the app and install with new user #519

Closed chetan-sevaro closed 1 year ago

chetan-sevaro commented 1 year ago

Hi, There is an issue where if User A has installed the app and then he uninstalled the app without logging out. Now if he installs with User B, he is still getting calls for User A.

How can I unregister User A as I won't have the deviceToken and accessToken after user uninstalls it

bobiechen-twilio commented 1 year ago

hi @chetan-sevaro

Thanks for reaching out and apologies for the delay of getting back to you. We currently don't have an easy way for the app or for the Twilio side to delete the notification binding. We have done some experiment and found that Apple actually updated the APNS behavior and will tell Twilio that a device token associated with the user app has been uninstalled. When Twilio receives such response from Apple, a 52141 The provided APNs device token has been unregistered error will be surfaced to the developer, and the push notification binding will be removed from the system. Next time when a call is made to this client identity, the call will end immediately and no incoming call notification will be delivered to the app user.

Please note that Apple has not clearly documented the frequency of the state refresh and we don't have any control if they decided to change the behavior in the future.

One suggestion for this problem is to only initialize the PushKit PKPushRegistry instance if the user has logged in, or whichever experience provided by the app. That way even when a push notification makes its way to the device, it won't be delivered to the app and we won't have to report incoming calls to CallKit.

-bobie