Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Firebase Cloud Message programmatically?

I'm starting to use firebase cloud messaging for my current app in order to send a notification. 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?

I would just use a local notification, but, I've already gone through the hell of setting up fcm already. (Plus, all my user data is in Firebase)

EDIT I've found out that Firebase Cloud Messaging has a function called FIRMessaging.messaging.sendMessage(message: message, to: , withMessageID, timeToLive)

I understand how this would work, but... I don't understand what it means by 'to' and 'withMessageID'. Could someone please explain this?

like image 524
Dowland Aiello Avatar asked Sep 06 '25 15:09

Dowland Aiello


1 Answers

The FIRMessaging.messaging.sendMessage(message: message, to: , withMessageID, timeToLive) is for sending upstream messages from iOS to server. 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

For implementing FCM server and sending downstream messages, read this(its pretty straight forward):

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

And here you are some github repos about FCM server:

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

like image 90
Pang Ho Ming Avatar answered Sep 09 '25 04:09

Pang Ho Ming