我正在使用 Sinch 和 ManagedPush 通过 PushKit 接收 VoIP 通知。在我的应用程序中,我有三种可能的状态:
- 在线的
- 离线
- “无法接听来电,但我可以拨打电话”
用户可以在 App 会话期间随时更改此状态。
以下文档: https ://www.sinch.com/docs/voice/ios/#unregisterapushdevicetoken
我正在使用unregisterPushNotificationDeviceToken以及stopListeningOnActiveConnection
这似乎可以使该人不接听来电,并且仍然让客户积极拨打电话。我遇到的问题是将用户重新设置在线。活动连接有效,但我似乎无法再次注册通知,以便在应用程序处于后台时接听电话。
Sinch SDK - 如何注销用户?不解决如何让用户重新上线。
我考虑过使用 SinchService 组件https://github.com/sinch/SinchService-iOS但我可以从代码中看到注销功能会终止客户端。而且我有兴趣不终止客户端,而是停止接收通知,然后在同一会话中再次接收它们。
我试过的:
不适用于来电按钮:
[_client stopListeningOnActiveConnection];
[_client unregisterPushNotificationDeviceToken];
在线按钮可以:
[_client startListeningOnActiveConnection];
[[UIApplication sharedApplication] registerForRemoteNotifications];
我调用 registerForRemoteNotifications 的原因是强制调用didRegisterForRemoteNotificationsWithDeviceToken委托方法,以便我可以调用托管推送以再次注册通知。我认为这可能会奏效,但事实并非如此。
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[self.push application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
这很可能不起作用,因为它通过 PushKit 并且注册方式不同。
对我有用的解决方法是在用户切换回在线状态时重新创建客户端:
[_client terminateGracefully];
_client = nil;
[self initSinchClientWithUserId:[BCDataProvider loggedInUser].callerId];
在 unregisterPushNotificationDeviceToken 之后,有什么方法可以让我重新注册 VoIP 通知,而无需重新创建客户端?
谢谢!!