How to send push notifications without using Firebase console(如何在不使用 Firebase 控制台的情况下发送推送通知)
问题描述
我有一个通过 Firebase 具有消息传递功能的应用.它在应用程序中工作,我有一个 firebase 观察者设置来实时获取新消息.我不知道该怎么做是在那个观察者下触发推送通知.
我已经在我的应用程序中实现了 Firebase 云消息传递,以便我可以向我的控制台发送通知,但是我无法找到适用于 iOS 的资源,或者不仅限于使用控制台发送单个资源消息.
我知道这是一个广泛的问题,它可能会被标记为离题",但如果我能找到更多相关资源,我将不胜感激!
有一个 API 用于使用 Firebase Cloud Messaging 发送消息.我建议您查看 FCM 服务器文档,而不是在这里重复.它基本上采用 HTTP POST 请求的形式,例如文档中的 example:
<块引用>POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1内容类型:应用程序/json授权:承载 ya29.ElqKBGN2Ri_Uz...HnS_uNreA{信息":{令牌":bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ...",通知" : {"body" : "这是一条 FCM 通知消息!","title" : "FCM 消息",}}}
要向
还有一个 Firebase Admin SDK,可以更轻松地调用 FCM 服务器 API 以在其支持的平台上发送消息.有关此选项的更多信息,请参阅 FCM Admin SDK 文档.这会将上面的内容变成这样(在 Node.js 上):
admin.messaging().send({信息":{令牌":bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ...",通知" : {"body" : "这是一条 FCM 通知消息!","title" : "FCM 消息",}}})
I have an app that has a messaging feature via Firebase. It works within the app and I have a firebase observer setup to grab new messages in realtime. What I don't know how to do is trigger push notifications under that observer as well.
I've implemented Firebase Cloud Messaging into my app so that I can send a notification to my console, but am having trouble finding a resource that is for iOS or that doesn't just end at using the console to send a single message.
I know this a broad question, and it might be labelled "Off-topic" but if I could be directed towards any more related resources, I'd greatly appreciate it!
There is an API for sending messages with Firebase Cloud Messaging. Instead of repeating it here, I recommend you check out the FCM server documentation. It basically takes the form of a HTTP POST request, such as this example from the docs:
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1 Content-Type: application/json Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA { "message":{ "token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification" : { "body" : "This is an FCM notification message!", "title" : "FCM Message", } } }
To send messages to devices you will need to specify the so-called FCM server key. As its name applies, this key should only be used in trusted environments, such as a server that you control, your development machine, or Cloud Functions for Firebase. The reason for this is that someone who has your FCM server key can send unlimited messages to all users of your app.
There is also a Firebase Admin SDK that makes it easier to call the FCM server API to send messages on platforms that it supports. For more on this option, see the FCM Admin SDK documentation. That turns the above into something like this (on Node.js):
admin.messaging().send({
"message":{
"token" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "This is an FCM notification message!",
"title" : "FCM Message",
}
}
})
这篇关于如何在不使用 Firebase 控制台的情况下发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在不使用 Firebase 控制台的情况下发送推送通知
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01