【发布时间】:2018-06-06 09:34:46
【问题描述】:
我在我的应用程序中实现推送通知。当有人向我发送消息时,我收到了针对该消息的数据,我想对收到的数据执行一些操作,但我无法获取值。这是我的代码。
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print("Received data message: \(remoteMessage.appData)")
guard let data = try? JSONSerialization.data(withJSONObject: remoteMessage.appData, options:.prettyPrinted),
let prettyPrinted = String(data: data, encoding: .utf8) else { return }
print("Received direct channel message:\n\(prettyPrinted)")
}
这是我的控制台输出。
Received data message: [AnyHashable("chat"): {"date":"1 second(s)
ago","img":"http:\/\/adforest-testapp.scriptsbundle.com\/wp-
content\/plugins\/adforest-rest-api\/images\/user.jpg","ad_id":"439","id":244,"text":"hi","type":"reply"},
AnyHashable("adId"): 439, AnyHashable("from"): 170168176816,
AnyHashable("title"): Honda Civic 2017 Type R, AnyHashable("message"):
hi, AnyHashable("senderId"): 47, AnyHashable("recieverId"): 1,
AnyHashable("topic"): chat, AnyHashable("type"): receive]
这是我的漂亮打印 JSON。 收到直接频道消息:
{
"chat" : "{\"date\":\"1 second(s)
ago\",\"img\":\"http:\\\/\\\/adforest-testapp.scriptsbundle.com\\\/wp-
content\\\/plugins\\\/adforest-rest-api\\\/images\\\/user.jpg\",\"ad_id\":\"439\",\"id\":244,\"text\":\"hi\",\"type\":\"reply\"}",
"adId" : "439",
"from" : "170168176816",
"title" : "Honda Civic 2017 Type R",
"message" : "hi",
"senderId" : "47",
"recieverId" : "1",
"topic" : "chat",
"type" : "receive"
}
请指导我如何从中获取关键值并用于执行某些操作。
【问题讨论】:
-
你想要什么上面的回应?
-
@JigarDarji 我想访问 ID、消息、类型等,但我无法访问它。
标签: ios firebase push-notification swift4