I am using Sinch with ManagedPush to receive notifications for VoIP via PushKit. In my app I have three possible states:
- Online
- Offline
- "Not available for incoming calls, but I can make calls"
The user can change this state at any time during the App session.
Following documentation: https://www.sinch.com/docs/voice/ios/#unregisterapushdevicetoken
I am using unregisterPushNotificationDeviceToken as well as stopListeningOnActiveConnection
This seems to work to get the person not to receive incoming calls and still having the client active to make calls. Where I am having issues is on setting the user back online. The active connection works, but I can't seem to be able to register again for the notifications, to receive the call when the app is in background.
Questions like Sinch SDK - How to logout user? don't solve how to put the user back online.
I have considered using the SinchService component https://github.com/sinch/SinchService-iOS but I can see from the code that the logout functionality terminates the client. And I am interested in not terminating the client, but stop receiving notifications and then receving them again on the same session.
What I have tried:
Not available for incomming calls button does:
[_client stopListeningOnActiveConnection];
[_client unregisterPushNotificationDeviceToken];
Online button does:
[_client startListeningOnActiveConnection];
[[UIApplication sharedApplication] registerForRemoteNotifications];
The reason I am calling registerForRemoteNotifications is to force the didRegisterForRemoteNotificationsWithDeviceToken delegate method to be called so I can call the Managed Push to register again for notifications. I thought that might do the trick but it didn't.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[self.push application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
Most likely this doesn't work because this goes through PushKit and the way to register is different.
As workaround that works for me is recreating the client when the user switches to online status back:
[_client terminateGracefully];
_client = nil;
[self initSinchClientWithUserId:[BCDataProvider loggedInUser].callerId];
Is there any way I can get back on being registered for VoIP notifications, after a unregisterPushNotificationDeviceToken without having to recreate the client?
Thanks!!