func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject])
{
PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Active
{
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
if let msg = userInfo["test"] as? Dictionary<String,AnyObject>
{
print(msg)
}
}
我的 userInfo["test"] JSON 值是:
> Printing description of userInfo:
▿ 3 elements
▿ [0] : 2 elements
- .0 : message
- .1 : 1235
▿ [1] : 2 elements
- .0 : aps
- .1 : 0 elements
▿ [2] : 2 elements
- .0 : link
- .1 :
我可以获取我的 userInfo 数据,但我不知道为什么我的 msg 没有任何值(甚至不是 nil,只是没有显示任何内容)
我怎样才能继续打印(msg)?
UPDATED
这是我的推送:
$this->parsepush->send( array( "channels" => ['test'], "data" => > $post_data ));
在 $post_data 示例中:
$post_data =
json_encode(数组
('链接' => $link, '消息' => $message));\
我已经尝试过指令,但我也无法进行简单的打印。
从用户信息中获取值
EDIT
仍然跳过了“aps”部分。
图片1
My JSON
这是我的Json
好像 :
> {
"aps":{
"alert":{
"title":"$title",
"body":"$message"
},
"badge":"1"
},
"adira":{
"link":"$link"
}
}
这是我的代码:
> func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
// PFPush.handlePush(userInfo)
// PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
if let msg = userInfo["message"] as? String {
print(msg)
print("a")
}
if let alertDict = userInfo["aps"]?["alert"] as? Dictionary<String, String> {
print("title : ", alertDict["title"])
print("body :", alertDict["body"]!)
print("badge: ", alertDict["badge"]!)
print("b")
}
if let link = userInfo["link"] as? String {
print(link)
print("c")
}
}
}
但我仍然无法得到我的aps
数据。仍然为零或什么都没有。
如果您想要特定的代码,只需点击下面的链接:
完整代码 AppDelegate.swift
EDIT 2
我直接使用 print(userInfo) ,打印输出是:
对象已保存。
[消息:iOS推送,aps:{ },链接:]
Update 2
我尝试从 parse.com 推送,而不是我的网站(第 3 方)。
这就是我从正常打印(userInfo)中得到的
> [aps: {
alert = 12345abc;
sound = default;
}]
所以我想我只需更改并添加一些内容到我的 JSON 从我的网站到:
[aps:{
alert = $message;
sound = default;
link = $link;
}]
类似的东西?