Xcode中 - 推送通知的Json(Xcode - Push Notification Json)

2019-10-21 03:24发布

我想推送通知发送到我的应用程序中包含自定义数据的JSON格式,但我不知道如何从中提取数据,或者如果连我的JSON格式是正确的。 (我认为这是因为解析将其发送成功)

从JSON解析:

{
    "aps": {
         "badge": 1,
         "alert": "Test",
         "sound": ""
    },
    "url": "http://www.google.com"
}

的appdelegate:

 func application(application: UIApplication, didReceiveRemoteNotification userInfo: NSDictionary!) {
  var notificationPayload: NSDictionary = userInfo["url"] as NSDictionary!

   if (notificationPayload["url"] != nil) {
     var url = notificationPayload["url"] as String

var feed: FeedTableViewController = navigation.viewControllers[0] as FeedTableViewController

      feed.messages.append(url)
      feed.sections.append("url")

  }else {
      PFPush.handlePush(userInfo)
    }
}

Answer 1:

试试这个:

func application(application: UIApplication, didReceiveRemoteNotification userInfo: NSDictionary!) {
    if let url = userInfo["url"] as? String {

        var feed: FeedTableViewController = navigation.viewControllers[0] as FeedTableViewController
        feed.messages.append(url)
        feed.sections.append("url")

    } else {
        PFPush.handlePush(userInfo)
    }
}


文章来源: Xcode - Push Notification Json