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

How to get push notification payload inside local notification

我正在 ios 开发 webRTC(视频通话)应用程序。每当用户在设备上收到传入的视频呼叫时,我都会收到来自服务器的 APNS 推送通知。

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

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

如果你想在本地推送通知中存储数据,那么你可以像这样添加数据,

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)