gpt4 book ai didi

ios - 为什么推送通知中的有效负载为零?

转载 作者:行者123 更新时间:2023-11-28 06:52:42 25 4
gpt4 key购买 nike

我使用 Parse.com 的推送服务将数据保存到推送通知,但是当我打印负载时。它似乎是零。为什么会发生这种情况,我该如何解决?谢谢。任何帮助表示赞赏。

func pushNotifications(){

let data = [
"alert" : "\(username!) wants you to listen to \(titleofsong) by \(artist)",
"identifier":"PlayerController", "title" : "test title", "artist" : "test artist"
]
let push = PFPush()
push.setQuery(pushQuery)
push.setData(data)
push.sendPushInBackgroundWithBlock {
success, error in

if success {
print("The push succeeded.")
} else {
print("The push failed.")
}
}
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
PFPush.handlePush(userInfo)
let title = userInfo["aps"]!["title"]
let artist = userInfo["aps"]!["artist"]
print(title)
print(artist)
}

最佳答案

根据documentation你的 APNS 负载应该看起来像

let data = [
"aps" : [
"alert" : [
"title" : "New Request",
"body" : "\(username!) wants you to listen to \(titleofsong) by \(artist)",
"action-loc-key" : "Listen"
],
],
"username" : "test user",
"identifier" : "PlayerController",
"title" : "test title",
"artist" : "test artist"
]

然后你可以提取标题和艺术家

let title = userInfo["title"]
let artist = userInfo["artist"]

关于ios - 为什么推送通知中的有效负载为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34469590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com