【问题标题】:Xcode - Push Notification JsonXcode - 推送通知 Json
【发布时间】:2014-12-04 20:09:23
【问题描述】:

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

来自 Parse 的 JSON:

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

应用代理:

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

【问题讨论】:

    标签: json xcode push-notification


    【解决方案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)
        }
    }
    

    【讨论】:

    • 是的,效果很好,我可以添加尽可能多的数据吗?例如:"url"、"date"、'category" 在 didLaunchWithOptions 函数中实现也很热门?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多