MrHertal / react-native-twilio-phone

Twilio Voice React Native module.
MIT License
154 stars 67 forks source link

How to re-register device token if it is updated or invalidated #37

Closed giangnt1 closed 3 years ago

giangnt1 commented 3 years ago

Twilio recommend implementing the following logic to check if the device token is updated or invalidated

- Invoke [TwilioVoice registerWithAccessToken:deviceToken:completion] the first time the App is launched
- Store the device token and the current time. This is necessary to determine if the device token has changed
- Implement PKPushRegistryDelegate and check when the token is updated or invalidated. Compare it to the token value stored in 2. If it has changed, invoke[TwilioVoice registerWithAccessToken:deviceToken:completion] and store the new device token value.
- Check when [TwilioVoice registerWithAccessToken:deviceToken:completion] was last invoked. If it has been over 6 months, register the token again to not let it expire.

Example: https://github.com/twilio/voice-quickstart-ios/blob/master/ObjcVoiceQuickstart/ViewController.m#L209

How can I implement this with react-native-twilio-phone? Is there any method to check the device token is updated?

MrHertal commented 3 years ago

Hi,

This is managed on iOS by RNTwilioPhone here

When token is updated, react-native-voip-push-notification is sending 'register' event. RNTwilioPhone will then fetch a new access token and call the register method.

Same thing happens on Android here, but the event is sent by react-native-firebase/messaging

giangnt1 commented 3 years ago

That means I don't need to do anything, RNTwilioPhone already managed the device token updated event, is that right? I just got an issue with register/unregister the device token, unable to make a call until I completely remove the application then re-install it and register the token again. I asked Twilio for help and they suggested implementing the token updated login above. Do you have any idea?

MrHertal commented 3 years ago

Ok are you able to reproduce this issue? Tell me the steps you did so I can reproduce.

Thanks.