首次启动时未收到推送通知
Push notification not recieved on first launch
我正在项目中使用sinch SDK。类型为 voip 的推送通知在第一次启动时未收到,但在许多 kill/open 应用程序后收到。
这是客户端的初始化
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)
}
}
}
我该如何解决这个问题
如果您想立即推送,请不要启动活动连接,活动连接会设置一个套接字,只要应用程序处于活动状态,您就会立即收到来电。
请问您为什么要在 init.你不应该那样做。如果您有登录注销功能,您应该在注销期间执行此操作,而不是初始化。你应该使用 terminateSuccesfully
if let _ = self.sinchClient{
self.sinchClient?.unregisterPushNotificationDeviceToken()
self.sinchClient?.stopListeningOnActiveConnection()
self.sinchClient?.terminate()
}
我通过移动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()
我正在项目中使用sinch SDK。类型为 voip 的推送通知在第一次启动时未收到,但在许多 kill/open 应用程序后收到。 这是客户端的初始化
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)
}
}
}
我该如何解决这个问题
如果您想立即推送,请不要启动活动连接,活动连接会设置一个套接字,只要应用程序处于活动状态,您就会立即收到来电。
请问您为什么要在 init.你不应该那样做。如果您有登录注销功能,您应该在注销期间执行此操作,而不是初始化。你应该使用 terminateSuccesfully
if let _ = self.sinchClient{
self.sinchClient?.unregisterPushNotificationDeviceToken()
self.sinchClient?.stopListeningOnActiveConnection()
self.sinchClient?.terminate()
}
我通过移动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()