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

标签 ios swift parse-platform push-notification

我使用 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/

相关文章:

ios - Parse.com SDK : What is the purpose of PFRelation?

android - 使用 Facebook 登录解析 - 可能从 APK v42 或 Graph API v2.4 开始

ios - 如何知道 iOS 应用程序提供试用版

ios - 不区分大小写的字符串搜索 - iphone

swift - 连字 SwiftUI 文本

swift - 为什么 Swift 1.2 破坏了 UIDynamicAnimator 的 init(collectionViewLayout :)?

ios - 将 Parse Server iOS swift 应用程序连接到 Heroku

ios - Safari View Controller 使用了错误的状态栏颜色

iphone - 在模拟器上的iOS 4.3上运行时,应用程序将崩溃

ios - 如何快速将 Airprint 方向设置为横向?