【问题标题】:How to get push notification payload inside local notification如何在本地通知中获取推送通知有效负载
【发布时间】:2017-07-23 04:29:03
【问题描述】:

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

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

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

【问题讨论】:

  • 感谢您的回答,我使用苹果 Voip 推送服务和 Pushkit 框架实现了它,它允许我在本地通知中处理我的有效负载,而应用程序处于后台或强制终止。

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


【解决方案1】:

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

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-06
    • 2016-07-19
    • 2017-05-31
    • 1970-01-01
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多