【发布时间】:2016-12-08 09:24:46
【问题描述】:
我现在在我的应用中设置了 Firebase 通知,当我发送消息时,消息会发送给我的应用的所有用户。 (我目前通过 Firebase 控制台发送消息)。我想要另一种不涉及 Firebase 控制台的发送推送通知的方式,并且我相信 HTTP Post 是一种简单的方式。如何使用 HTTP Post 远程发送推送通知?
【问题讨论】:
标签: ios swift http firebase push-notification
我现在在我的应用中设置了 Firebase 通知,当我发送消息时,消息会发送给我的应用的所有用户。 (我目前通过 Firebase 控制台发送消息)。我想要另一种不涉及 Firebase 控制台的发送推送通知的方式,并且我相信 HTTP Post 是一种简单的方式。如何使用 HTTP Post 远程发送推送通知?
【问题讨论】:
标签: ios swift http firebase push-notification
因评论而编辑: 请确保不将服务器密钥包含在您的客户端中。有办法“为不那么伟大的人”找到它并做一些事情...... 实现这一目标的正确方法是让您的客户端指示您的应用服务器发送通知。
您必须向 Google-API-Endpoint 发送 HTTP-Post。
您需要以下标题:
Content-Type: application/json
Authorization: key={your_server_key}
您可以在 Firebase-Project 中获取您的服务器密钥。
HTTP-Post-Content:示例
{
"notification": {
"title": "Notification Title",
"text": "The Text of the notification."
},
"project_id": "<your firebase-project-id",
"to":"the specific client-device-id"
}
示例设备 ID:
cc6VGMjpIiA:APA91bGLpm5Z2p0NNh7nxttCTVd1tTsL2jObDaS9U8G1YjDjkpwkBlRLjU89ns4ujQ7rFU1Z2NshpUAX2RiQiIDKhHJdB0RtSS3H6nTT-lGEkIpzVtVzJpLIVqzSVbRjmyYlxD3BSLZl
您必须将此请求发送至https://fcm.googleapis.com/fcm/send。
截至目前,无法使用 API 向所有设备发送通知。您必须为此使用 Firebase-Console。
我喜欢使用 Chrome 插件“邮递员”来发送 API 请求,因为您可以保存 HTTP 请求。很舒服。
你也可以使用 curl。
curl
-X POST
-d "{ "notification": {
"title": "Notification Title",
"text": "The Text of the notification."
},
"project_id": "<your firebase-project-id",
"to":"the specific client-device-id"
}"
-H "Content-Type: application/json"
-H "Authorization: key={your_server_key}"
https://fcm.googleapis.com/fcm/send
【讨论】: