2016-11-10 101 views
1

我在項目中使用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) 

     } 

    } 

} 

我怎麼能如果你想推就不要開始aactive連接,主動解決此

回答

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() 
0

連接會建立一個套接字,只要應用程序處於活動狀態,您將立即獲得來電。

請問你爲什麼要在init中這樣做?你不應該這樣做。如果你有登錄註銷功能,你應該這樣做,註銷,而不是初始化。並且應該使用terminateSuccesfully

if let _ = self.sinchClient{ 
    self.sinchClient?.unregisterPushNotificationDeviceToken() 
    self.sinchClient?.stopListeningOnActiveConnection() 
    self.sinchClient?.terminate() 
} 
+0

我修改了代碼等你解決了這個問題推薦。這個問題沒有解決。在我終止應用程序並重新打開之前,不會收到推送通知。 –