Xcode - 推送通知Json
问题描述:
我想发送一个推送通知给我的应用程序的JSON格式包含自定义数据,但我不知道如何从中提取数据,或者如果我的JSON格式是正确的。 (我认为这是因为解析成功将其发送)Xcode - 推送通知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)
}
}
答
试试这个:
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”,“日期”,“类别” 也热来实现它的功能didLaunchWithOptions – Abdou023 2014-10-09 23:31:49
只要它是小于256个字节http://*.com/a/9183146/2611971 – Logan 2014-10-10 00:24:16