Our goal is sending notifications to groups of devices from our backend, and only from server side is possible to know which device should receive the notification.
We've done some attempts with AppCenter because we mostly work with Xamarin iOS/Android/Forms, but now we have the doubt that it's probably better to use directly Firebase API because wider and more powerful.
I see that with new version of API (HTTP V1) is not possible to send a notification to a list of tokens, feature that was available in legacy API using registration_ids parameter (https://firebase.google.com/docs/cloud-messaging/send-message).
Device group name (legacy protocols only)
I cannot use topics because when it's time to send the communication is a server's responsibility to prepare the "mailing list" for notifications.
I was thinking to use device group messaging (https://firebase.google.com/docs/cloud-messaging/android/device-group) but these are part of the legacy api, and I'm not sure if it makes sense/it's possible to use them with new version of API.
Is an option to send a batch of 100-200-500 push notifications each one to only one token? In theory there isn't a limit to notifications which is possible to send, but I'm worried that sending too many of them I could risk to be banned.
Is it better to use legacy API? Also AppCenter (Microsoft) uses legacy API, it's evident because of how the setup works and because from AppCenter's console it's possible to send notifications to a list of tokens, feature unavailable on Firebase's console.
Another person just asked something similar but the answer was to use topics (How to send firebase notification for all user at a time?).
Got here from the link in your comment in my answer here. And just to reiterate my response there, when sending messages to multiple tokens with v1, the suggested approach now is to use Topics Messaging, since registration_ids is not supported.
Is it better to use legacy API?
v1 was described as the more secure, cross platform, future proof way of sending messages to FCM clients. More secure since it uses OAuth2 security model.
However, if your use-case is better with using the legacy API, then I suggest you go ahead with using it.
This page suggests that you should stay with the legacy API if you want to continue to use the multicast feature: https://firebase.google.com/docs/cloud-messaging/migrate-v1
Any apps that use device group messaging or multicast messaging, however, may prefer to wait for future versions of the API. HTTP v1 does not support these features of the legacy API.
Related
I'm learning Flutter myself and need some expert guidance on the right way to do what I want.
I would like to allow the user of my Flutter application to securely send some sensitive data (e.g. email, phone number, name etc.) to my PHP based website (with REST API) and then, after some time, I would like to send a reply (e.g. . text) from my website to the sender's device and displaying it on the User's screen.
I suspect I should use Firebase Cloud Messaging for this - am I right?
I found tutorials that explain how to send data from Flutter-> FCM and from PHP(curl)-> FCM. But I can't find the tutorial explaining how to send data from Flutter-> FCM-> PHP?
Firebase Cloud Messaging is typically used to send messages from the server to the application, when the user may not be actively using it. While it can be used to send messages from the client to a server, it is much less common for that.
That's because calling a PHP API from your Flutter app is no different than retrieving any data from the internet, and can be accomplished in a multitude of ways. One of the simpler approaches is documented in Flutter's fetching data from the internet page and uses the http package.
I'm struggling to find an answer on if Firebase Cloud Messaging supports sending notifications to Device Groups in the v1 HTTP API.
According to the migration documents, sending to device groups is supported.
Caution: Any apps that use device group messaging must continue to use the legacy API for the management of device groups (creating, updating, etc.). The HTTP v1 can send messages to device groups, but does not support management.
The important part being "HTTP v1 can send messages to device groups"
I'm using the firebase-admin-python SDK, and when sending a single or set of batch messages I get a successful response, but the push notification does not send.
Is sending to device groups actually supported by the SDK in the same way that firebase_admin.messaging.send and firebase_admin.messaging.send_all are? The statement above leads me to believe that they are, but pushes aren't delivering (they do deliver when using the older legacy FCM API)
I assume you mean the token parameter. There's no sparameter named to on Message.
The documentation you're quoting is for the HTTP v1 API. And it might very well support sending to device groups -- although I haven't been able to find any examples to confirm that. But I know for sure that the SDKs (all expect the Node.js SDK) neither expose nor support any functionality for sending to device groups. Docs at https://firebase.google.com/docs/cloud-messaging/send-message outline all the different ways you can send a message using the Python SDK, and it makes no mention of sending to device groups. The Message.token parameter must be given an individual device registration token.
It is however rather strange that the FCM backend does not return an error when passing a device group key as the token. I'd recommend reporting a bug for that.
On this page they explain Web Push with Service Workers stating
Chrome currently uses Firebase Cloud Messaging (FCM) as its push service. FCM recently adopted the Web Push protocol. and then explaining Firebase and so on...
Since the Service Worker gives me a unique endpoint and a pubkey, it seems to me that technically it should be possible to use that endpoint directly, without anything additionally - except if Google deliberally forces a registration.
I mean, just send a POST request to that endpoint, sending just the notification data encrypted/authenticated using the pubkey without any "VAPID".
Do I absolutely need a Firebase account or is it possible to access the endpoint directly (without additional registration) if I just want to send a notification to a single device?
It's 2021 and all major browsers implement a push service and support VAPID now. You use a web push library (Javascript, Python, C#,..) of choice.
There is no need to register anywhere.
The technical mechanism in short is this:
You generate two VAPID keys once using the push library. One key is private and one is public.
The public key is used in the javascript as "application server key" when subscribing to the push service of the browser.
If the subscription is successful you receive a subscription object from the browser containing an endpoint and two additional keys.
The endpoint is an address depending on the web browser / manufacturer and the service it is currently using. The endpoints look like (Oct 2021) e.g.
Google Chrome h_tt_ps://fcm.googleapis.com/fcm/send/cz9gl....., Microsoft Edge h_tt_ps://wns2-par02p.notify.windows.com/w/?toke....., Mozilla Firefox h_tt_ps://updates.push.services.mozilla.com/wpush/v2/gAAAAABhaUA....
If your server program has this information (endpoint and keys from subscription object) it can send a push message to the endpoint with the push library. The corresponding service in the web, hosted by the manufacturer sends this to the browser's service on the device.
There is the PushAPI which shall get used.
But it doesn't is supported by every Browser at the moment.
You can find nice examples in the Service Worker Cookbook of Mozilla
I have the existing app that using GCM and have some issue with GCM reliability. I interested using FCM to replace the GCM, but I doubt about compatibility. I've some google search but still couldn't find a satisfactory answer, here some link:
Migrating from gcm to fcm on android
If FCM inherits from GCM, does FCM also support GCM token? Or we need to some config in the server (using gcm-http.googleapis.com/gcm/ vs. fcm.googleapis.com/fcm/request in one server?)
I still doubt to migrating GCM to FCM, so I need some ideas from you all guys and I think send a notification from FCM console is not scalable for me because of too many notifications that triggered by user activities. Thanks
As much as I have understood from reading various documents and watching youtube recordings of 2016 I/O, FCM appears to be rebranded GCM. Server side integration will stay the same with option to switch endpoint domain name. When look a little closer you see that both domain names are referring to same IP address.
From client side integration much more has changes. FCM has a new SDK which makes certain things little easier to manage. Not sure if there are any improvements in terms of keeping app connected to the backend, listening incoming messages.
So my requirements in mind are I have an application continuously running on a phone and I need to be able to push events to this application from time to time.
The application will primarily pull data from the server but sometimes the server will have urgent data it needs to send to the phone. I also have as a requirement to send the notification to a very specific phone, which the application will have a unique identifier associated with that phone. So I'm not looking for a simple broadcast solution.
Polling a web service by the application on a frequent time interval seems like it would impact a data plan too much, plus battery usage of the device. So I'd like to avoid a polling solution if possible.
What would be a good way to accomplish this?
I recently used PubNub to send push notifications to a web app in lieu of Web Sockets. PubNub has SDKs for all sorts of languages. Their long polling method is extremely fast and efficient. You can map messages to different devices based on the UUID of the channel. At first it seems like a simple broadcast solution (and Pubnub can be used this way), but we were able to create unique sessions with a relative amount of ease.
http://www.pubnub.com/developers/
I do not quite understand if you want to build the application yourself or if you are looking for one.
I use Pushover to do this. Pushover runs on Android, iPhone, iPad, and Desktop. It supports multiple message priorities. You can do a http POST with a unique ID and message to send a message to a unique device.
Pushover has it's own API and is really easy to use.
Polling can indeed be costly in terms of data and battery. The most efficient way to send data from the server to a phone is using Push Notifications (iOS) or Google Cloud Messaging (Android). Both notification types can be implemented directly by the developer or by making use of an API.
Golgi is an SDK that produces custom type safe communication APIs. The APIs produced have full support for both Push Notifications and Google Cloud Messaging.