Method didInvalidatePushTokenForType is not calling on token expired using Twilio

不想你离开。 提交于 2019-12-11 05:35:45

问题


I am using Twilio Voice Objective-C Quickstart for iOS. I am able to register TwilioVoice after creating access token as mentioned below:-

#pragma mark - PKPushRegistryDelegate
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
    NSLog(@"pushRegistry:didUpdatePushCredentials:forType:");

    if ([type isEqualToString:PKPushTypeVoIP]) {
        self.deviceTokenString = [credentials.token description];

        [[PhoneCallModel sharedInstanse] getAccessTokenResponse:^(NSString *accessToken) {

            [[TwilioVoice sharedInstance] registerWithAccessToken:accessToken
                                                      deviceToken:self.deviceTokenString
                                                       completion:^(NSError *error) {
                                                           if (error) {
                                                               NSLog(@"An error occurred while registering: %@", [error localizedDescription]);
                                                           }
                                                           else {
                                                               NSLog(@"Successfully registered for VoIP push notifications.");
                                                           }
                                                       }];
        }];
    }
}

I have created token for 5 mins, as per Pushkit (PKPushRegistry) method

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type

should call after token expired. But didInvalidatePushTokenForType is not calling, tried many times.

How can I check that current access token is expired or not, passed in 'registerWithAccessToken'?
I want to re-register TwilioVoice With AccessToken after current access token expired.

Please help, thanks in advance.


回答1:


Twilio developer evangelist here.

Wanted to complete the circle here, as this question was also asked and may have follow up on the GitHub project for the quickstart application. Here's the answer from Bobie who works on the Programmable Voice SDK team:

The - (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type delegate method is called when the device token previously issued by Apple VoIP service has expired or no longer valid for use. More details in this documentation by Apple.

The main idea of using Access Token is to provide a "one-time" operation authentication, for registration requests or the signaling handshake when making outgoing calls. That being said, we still recommend that you generate access tokens with expiry equal or longer than 1 hour when making outgoing calls.

As for refreshing the registry, you actually don't have to re-register unless you have explicitly unregistered (or the PushKit token has expired). The application will still be able to receive push notifications from Twilio.

Just to add to this, if you want to get automatic access token management in your application, then you can use the Twilio AccessManager SDK. This is a common SDK that is shared among Programmable Voice, Chat, Video and Sync. There are instructions for installing it in the Chat documentation.

This page then shows how to use the AccessManager with the Chat SDK. You can substitute the Programmable Voice SDK and it should work the same though.

Let me know if this helps at all.



来源:https://stackoverflow.com/questions/45323827/method-didinvalidatepushtokenfortype-is-not-calling-on-token-expired-using-twili

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!