我正在项目中使用sinch SDK。类型为voip的推送通知在首次启动时未收到,但在许多终止/打开应用程序后收到。 这是客户端的初始化
func initSinchClient(userIdentifier : String!) -> SINClient! {
if let _ = self.sinchClient{
self.sinchClient?.unregisterPushNotificationDeviceToken()
self.sinchClient?.stopListeningOnActiveConnection()
self.sinchClient?.terminate()
}
self.sinchClient = Sinch.client(withApplicationKey: SinchConstants.SinchAppKey, applicationSecret: SinchConstants.SinchApplicationSecret, environmentHost: SinchConstants.SinchEnvironmentHost, userId: userIdentifier)
self.sinchClient!.delegate = self
self.sinchClient!.call().delegate = self
self.sinchClient!.setSupportActiveConnectionInBackground(true)
self.sinchClient!.setSupportPushNotifications(true)
self.sinchClient!.setSupportCalling(true)
self.sinchClient?.enableManagedPushNotifications()
self.sinchClient!.start()
self.sinchClient!.startListeningOnActiveConnection()
if let pushTokenData = UserDefaults.standard.object(forKey: "PushNotificationToken"){
self.sinchClient!.registerPushNotificationData((pushTokenData as! NSData) as Data!)
}
return sinchClient
}
这是我设置令牌
的时候func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
// Register VoIP push token (a property of PKPushCredentials) with server
if let sinchCLient = SinchManager.sharedInstance.sinchClient{
if let _ = SessionManager.sharedInstance.user {
sinchCLient.registerPushNotificationData(credentials.token)
}
}
}
我该如何解决这个问题
答案 0 :(得分:2)
我通过移动VOIP推送注册来解决问题
let mainQueue = dispatch_get_main_queue()
// Create a push registry object
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
// Set the registry's delegate to self
voipRegistry.delegate = self
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [PKPushTypeVoIP]
在初始化推送对象实例化和配置之前
self.push = Sinch.managedPushWithAPSEnvironment(.Production)
self.push!.delegate = self
self.push!.setDesiredPushType(SINPushTypeVoIP)
self.push!.registerUserNotificationSettings()
答案 1 :(得分:0)
如果您想立即推送不要启动无效连接,则活动连接会设置套接字,只要应用程序处于活动状态,您就会立即收到来电。
我可以问你为什么要在init中这样做。你不应该这样做。如果你有登录注销功能,你应该这样做duriong注销,而不是init。你应该使用terminateSuccesfully
if let _ = self.sinchClient{
self.sinchClient?.unregisterPushNotificationDeviceToken()
self.sinchClient?.stopListeningOnActiveConnection()
self.sinchClient?.terminate()
}