解析为Firebase增强推送通知
问题描述:
我正在将解析迁移到Firebase,并且遇到增强推送通知问题。解析为Firebase增强推送通知
解析数据(iOS的侧)是象:
{"ast":
{"alert": {
{"body": "body_test",
"title": "title_test",
"description": "description",
"endpoint-proposal": "https://.."
"launch-image": "https://..."
},
"sound": "chime",
...
}
与火力地堡API工作的AST标签是[ '通知'] [ '体']。
如果我送
['notification']['body'] = 'Hello'
它完美并生成以下推:
{"ast":
{"alert": "Hello"}
}...
所以,问题就在这里,我要送一本字典在标签(警报)和我不能这样做,因为firebase将该值设置为字符串。
例在python:
alert = dict()
alert['title'] = 'title'
alert['description'] = 'description'
alert['endpoint-proposal'] = 'https://..'
alert['launch-image'] = 'https://..'
fcm_payload['notification']['body'] = alert
send_push()
而在iOS的身边,我得到:
[AnyHashable("gcm.message_id"): 0:123456789,
AnyHashable("aps"): {
alert = "{\"body\": \"body\",
\"launch-image\": \"https://...\",
\"endpoint-proposal\": \"https://...\",
\"description\": \"description\",
\"title\": \"title\"}";
}]
始终为字符串:S
有什么方法来发送警报的字典?
答
notification
body
参数将永远被FCM视为String
。这只是行为。什么你需要做的就是利用data
有效载荷,并在您的自定义键 - 值对:
在iOS上,如果通过APNS发送消息,其表示自定义数据字段。如果通过FCM连接服务器发送,则会在AppDelegate应用程序中显示为键值字典:didReceiveRemoteNotification:。
更多细节可以在这Receiving Messages in iOS文档中看到。我认为对于您的情况,您只需在您的有效负载中一起使用notification
和data
参数。
答
json.loads()应该给你一个字典。
已经过测试。无论如何,它始终将值设置为字符串。 – giopromolla