访问自定义推送通知有效负载

时间:2018-07-16 17:45:27

标签: ios swift xcode

我正在使用boolXcode 9.4.1 (9F2000)

我正在使用这些数据进行推送通知:

Swift 3

这是我所拥有的功能:

{
    "aps":{
        "alert":{
            "title":"Hello",
            "body":"How are you?"
            },
            "badge":0,
            "sound":"default",
            "my_value":"This is a test!"
    }
}

我认为自定义有效负载应位于func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let action = response.actionIdentifier let request = response.notification.request let content = request.content print("payload data: \(action)\(request)\(content)\n") completionHandler() } request中。但是当执行content时,它不会出现。

我在做什么错了?

1 个答案:

答案 0 :(得分:3)

您可以使用以下字典

let content = response.notification.request.content.userInfo
if let aps = content["aps"] as? [String: AnyObject] {
    let myValue = aps["my_value"]
    // DO STUFF, in myValue you will find your custom data
}