0

我正在使用 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 通知,而无需重新创建客户端?

谢谢!!

4

1 回答 1

0

如果我没记错的话,基本上你需要实现VOIP,通过在线/离线等你需要管理用户是否允许通话。

您可以使用套接字架构,使广播用户在线/离线,因此您可以在此基础上管理是否允许呼叫。

如果您正在使用 VOIP,则必须使用以下方法。

-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
     ///tell the Sinch SDK about the push token so we can 
     ///give that to users that want to call this user.
    [_client registerPushNotificationData:credentials.token];
}

下面提到的方法将不会被使用。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

  
}

使用推送通知,将始终为您提供新的唯一设备令牌,因此一旦您取消注册离线,然后再次在线您将无法使用相同的设备令牌注册。

使用推送工具包(静默推送通知),您将始终在未注册后获得相同的设备令牌注册。

于 2016-10-06T11:22:46.600 回答