I am thinking about keeping all registration ids(push token) in DB and sending notifications to user from iPhone. I tried something like this but did not get any notification.
func sendPNMessage() {
FIRMessaging.messaging().sendMessage(
["body": "hey"],
to: TOKEN_ID,
withMessageID: "1",
timeToLive: 108)
}
What I am doing wrong or maybe it is impossible at all?
Diego's answer is very accurate but there's also cloud functions from firebase it's very convenient to send notifications in every change in the db. For example let's say you're building chat application and sending notification in every new follower change. This function sample is very good example.
For more information about cloud functions you can check official docs.
Google Cloud Functions make it now possible send push notifications from device-to-device without an app server.
From the Google Cloud Functions documentation:
Here is a demo project for sending device-to-device push notifications with Firebase and Google Cloud Functions.
Use onesignal,you can send device to notifications or device to segments ,it can work with firebase in this way Use onesignal functions to create a specific id,save it in a firebase database ,then when the id can be put in another function that is used to send a notification Notes: 1-i am using it in my apps with firebase works perfectly 2-i can submit that code,just someone comments so i can find this answer
Currently it's not possible to send messages from the application itself. You can send messages from the Firebase Web Console, or from a custom server using the server-side APIs.
What you might want to do is to contact a server (like via http call) and that server will send the message to the user. This way ensure that the API-KEY of the server is protected.
PS: the
sendMessage(..)
api is called upstream feature, and can be used to send messages from your app to your server, if you server has an XMPP connection with the FCM server.Yes you can send push notification through Firebase.Please make sure do NOT include the server-key into your client. There are ways "for not so great people" to find it and do stuff... The Proper way to achieve that is for your client to instruct your app-server to send the notification.
You have to send a HTTP-Post to the Google-API-Endpoint.
You need the following headers: