如何在本地通知中获取推送通知有效负载

时间:2017-03-03 06:53:47

标签: push-notification swift3 apple-push-notifications ios10 uilocalnotification

I want to achive this from local notification WhatsApp Incoming Video Call我正在开发ios中的webRTC(视频通话)应用程序。每当用户在设备上收到传入的视频通话时,我都会收到来自服务器的APNS推送通知。

{
    "aps" : {
        "alert" : "Incoming video call from - Bob",
        "badge" : 1,
        "sound" : "bingbong.mp3",
        "userdata" : {JSON}
    }
}

如何将其存储在本地通知中?

1 个答案:

答案 0 :(得分:2)

如果要在本地推送通知中存储数据,则可以添加如下数据

let interval = TimeInterval(1)
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: false)
let content = UNMutableNotificationContent()
content.title = "Incoming video call from - Bob"
content.body = "Your body"
content.sound = UNNotificationSound.init(named: "CustomSound.mp3")
content.badge = "Your badge number"
content.userInfo = ["userData": YOUR_USER_DATA from remote]
let req = UNNotificationRequest(identifier: "localPushNotification", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(req, withCompletionHandler: nil)