接收来自Sinch,Swift 3的推送通知

时间:2017-06-15 08:54:06

标签: ios swift push-notification sinch

我遇到以下问题:我收到推送通知,但推送通知的标题和正文未显示。推送通知仅显示我在localizable.string中定义的内容,而不是我在代码中定义的内容。我的app delegate中有以下代码:

// SINManagedPushDelegate - FORWARD INCOMING PUSH NOTIFICATIONS TO A SINCH CLIENT


    func managedPush(_ unused: SINManagedPush, didReceiveIncomingPushWithPayload payload: [AnyHashable: Any], forType pushType: String) {

        }

    //Describes what happens with handleRemoteNotfication from above


    func handleRemoteNotification(_ userInfo: [AnyHashable: Any]) {

        let result: SINNotificationResult = (self.client?.relayRemotePushNotification(userInfo))!

        if !(self.client != nil) {
            let userId: String? = UserDefaults.standard.object(forKey: "userId") as! String?
            if userId != nil {
                self.initSinchClientWithUserId(userId: userId!)
            }
        }

        if result.isCall() && result.call().isTimedOut {

              if #available(iOS 10.0, *) {

                let content = UNMutableNotificationContent()

                content.categoryIdentifier = "awesomeNotification"
                content.title = "Missed Call"
                content.body = String(format: "Missed Call from %@", arguments: [result.call().remoteUserId])
                content.sound = UNNotificationSound.default()


            }
              else {


            let alert: UIAlertController = UIAlertController(title: "Missed Call", message: String(format: "Missed Call from %@", arguments: [result.call().remoteUserId]), preferredStyle: .alert)
            let okAction = UIAlertAction(title: "Ok", style: .default, handler: {_ -> Void in
                alert.dismiss(animated: true, completion: nil)
            } )

            alert.addAction(okAction)

            self.window?.rootViewController?.present(alert, animated: true, completion: nil)
            }

        }

        self.client?.relayRemotePushNotification(userInfo)

    }

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

   // func application(_ application: UIApplication, didReceiveRemoteNotification data: [AnyHashable : Any]) {

        print("Push notification received: \(userInfo)")

        print("Remote Notification")
        self.sinchPush.application(application, didReceiveRemoteNotification: userInfo)


    }


    // implementation of SINCallClientDelegate - PRESENTING LOCAL NOTIFICATIONS FOR INCOMING CALLS

    private func client(_ client: SINClient, localNotificationForIncomingCall call: SINCall) -> SINLocalNotification {


        let notification = SINLocalNotification()
        notification.alertAction = "Answer"
        notification.alertBody = "Incoming call from \(call.remoteUserId)"
        return notification



    }

它也不起作用,如果通话超时,我会收到通知。

谁可以帮忙?非常感谢

1 个答案:

答案 0 :(得分:0)

你只能在推动VoiP推送时定义你想要看到的内容,这就是你看到你所看到的内容的原因。