简体   繁体   English

以编程方式发送Firebase云消息?

[英]Send Firebase Cloud Message programmatically?

I'm starting to use firebase cloud messaging for my current app in order to send a notification. 我开始为我当前的应用程序使用firebase云消息传递以发送通知。 The only problem is, the message is triggered from an element inside the app. 唯一的问题是,消息是从应用程序内的元素触发的。 If an individual would want to trigger a notification programmatically, how would they do it (still using fcm) in swift? 如果一个人想要以编程方式触发通知,他们将如何在swift中执行此操作(仍然使用fcm)?

I would just use a local notification, but, I've already gone through the hell of setting up fcm already. 我只想使用本地通知,但是,我已经经历了设置fcm的地狱。 (Plus, all my user data is in Firebase) (另外,我的所有用户数据都在Firebase中)

EDIT I've found out that Firebase Cloud Messaging has a function called FIRMessaging.messaging.sendMessage(message: message, to: , withMessageID, timeToLive) 编辑我发现Firebase Cloud Messaging有一个名为FIRMessaging.messaging.sendMessage的函数(消息:消息,to:,withMessageID,timeToLive)

I understand how this would work, but... I don't understand what it means by 'to' and 'withMessageID'. 我理解这是如何工作的,但是......我不明白'to'和'withMessageID'意味着什么。 Could someone please explain this? 有人可以解释一下吗?

The FIRMessaging.messaging.sendMessage(message: message, to: , withMessageID, timeToLive) is for sending upstream messages from iOS to server. FIRMessaging.messaging.sendMessage(message: message, to: , withMessageID, timeToLive)用于将上游消息从iOS发送到服务器。 First of all, is this the use case you are looking for? 首先,这是您正在寻找的用例吗? Or you want to send message from server to device(downstream)? 或者您想要从服务器向设备(下游)发送消息?

For sending upstream messages, read this might help : 要发送上游消息,请阅读这可能有所帮助:

https://firebase.google.com/docs/cloud-messaging/ios/upstream https://firebase.google.com/docs/cloud-messaging/ios/upstream

For implementing FCM server and sending downstream messages, read this(its pretty straight forward): 要实现FCM服务器并发送下游消息,请阅读此内容(非常简单):

https://firebase.google.com/docs/cloud-messaging/server https://firebase.google.com/docs/cloud-messaging/server

And here you are some github repos about FCM server: 在这里你是一些关于FCM服务器的github回购:

https://github.com/search?utf8= ✓&q=fcm+server https://github.com/search?utf8=✓&q= fcm + server

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM