Xcode-推送通知Json



我想以Json格式向我的应用程序发送一个包含自定义数据的推送通知,但我不知道如何从中提取数据,也不知道我的Json格式是否正确。(我认为这是因为Parse发送成功)

Json来自Parse:

{
    "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)
    }
}

试试这个:

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)
    }
}

最新更新