Best way to implement push notifications with Firebase
Asked Answered
D

7

12

I am an iPhone app coder, and I'm using Firebase as my backend server. Firebase doesn't support Push Notifications, so I've been trying to figure out how to include them in my app. I've read this question: How to send an alert message to a special online user with firebase but it seems like more of a work-around than an actual solution.

Is there an answer on how to do this? Are there third parties or APIs that might seemlessly implement this functionality?

One solution I have tried is to use Zapier to connect Firebase to Pushover.

At this point, I've been able to observe events in the app that I'm coding and then get notifications in a pushover app on my iphone. However, ideally, I'd like to receive the notifications in my app, not in the pushover app, because I don't want users to need to have pushover in order to use my app and because I want users to receive their own distinct notifications, not notifications for everyone.

Does anyone have suggestions on how I should handle this issue?

Thanks for the help!

EDIT This isn't a duplicate of this question: Does firebase handle push notifications? because I know Firebase doesn't directly handle push notifications. I'm looking for the best indirect way of handling push notifications with Firebase.

Dade answered 7/1, 2016 at 16:56 Comment(5)
Possible duplicate of Does firebase handle push notifications?Chainey
No, this isn't a duplication because I know Firebase doesn't directly handle push notifications. I'm looking for ways to do push notifications even though Firebase doesn't handle them directly. @ChaineyDade
Actually, as of today (May 19 2016) Google just rebranded GCM to Firebase Cloud Messaging and it offers this feature. See this response for a more complete answer.Feudalize
See here My Demo => Demo Code here on StackoverflowColugo
See here My Demo => Demo Code here on StackoverflowColugo
L
13

Now Google rebranded GCM to Firebase Cloud Messaging and it now offers this cross platform service. Firebase also offers notifications.

These are the differences between these two services:

Firebase Cloud Messaging provides a complete set of messaging capabilities through its client SDKs and HTTP and XMPP server protocols. For deployments with more complex messaging requirements, FCM is the right choice.

Firebase Notifications is a lightweight, serverless messaging solution built on Firebase Cloud Messaging. With a user-friendly graphical console and reduced coding requirements, Firebase Notifications lets users easily send messages to reengage and retain users, foster app growth, and support marketing campaigns.

If you want a more detailed comparison. Read this.

Larder answered 23/5, 2016 at 1:25 Comment(0)
P
7

If you want device to device push messages and not just server to device, the only solution I found was OneSignal. I was able to add basic device to device push message support for my app in about an hour and it is currently free.

Both Batch and Firebase only support server to device push messages, not what you want for a chat app

Procaine answered 29/6, 2016 at 21:14 Comment(4)
Batch supports client-side push notifications as well by using the Transactional API directly from app code. Basic example with our Swift client.Grobe
I did not conclude from the Transactional API description that it was supported: "The Batch transactional API is a RESTful API that lets you to send notifications from your own systems to specific users, based on their device token or your own user ids" I thought your own systems were your servers to run the campaign. Furthermore, you need to be a Premium, Pro, or Enterprise users: "The transactional API allows you to target up to 10,000 push tokens and is available for Premium, Pro and Enterprise users"Procaine
As soon as you have access to an open API, you can call it from wherever you want (server-side code or client-side code), it's valid for Batch and all other push notification providers.Grobe
Hi @n6xej, can you please point me to any documentations which shows on how to use device to device push messages using the OneSignal? I am not finding any such documentations. Thanks.Fireweed
O
2

There are a couple of options: (well, more than a couple but here's two)

Parse handles push notifications very very well - they have that down pat and it's super simple. However, you may have issues with users and accounts - depending on what your app does.

You mentioned Pushover. We worked their API a while back but not through Zapier. If I remember correctly, I believe you can simply register your app, send an HTTPS: request to their server and then the notifications are sent from/to your app.

Also, you may want to evaluate how you are using push as it's possible you can roll a notification-like event just into the app itself.

Orndorff answered 7/1, 2016 at 19:7 Comment(10)
Thanks @Jay, a solution that I've been looking into is using node.js to listen for changes to specific Firebase directories like this question suggests: #28686638 but it's difficult to learn how to implement this. Are there examples that you've seen?Dade
Hi @PhilipSopher, I just implemented a Parse and Firebase setup -- I don't have the example online yet, but can help with any specific questions. Like you mentioned, you can have a node.js server listen for changes on the Firebase data. In Parse, you associate a user's installation (containing their device token) to a firebase user (e.g., with a uid). Once the firebase data that you're listening to changes, your node.js server receives the a child_added event from Firebase and you can look up the associated user in ParseCida
@Cida are you using Parse just for sending push notifications, or does it have other uses in your app? I'd love to see the code example when you have it online!Dade
I don't know if leveraging node.js is really necessary. Your app will receive events from Firebase and when it receives one that should be pushed, just sent it to Parse for the client push notifications. It's a pretty simple setup other than handling the user aspect - determining which is better for user Auth; Parse or Firebase.Orndorff
@Cida how do you, as you say, associate a Parse user's installation to a Firebase user? Does that have to be done during login? The other step I'm confused about is how to create a node.js listener. Thanks again for the help!Dade
@Orndorff as you say, handling the user aspect seems complex! Do you have a code sample for how to do this? Where in the code do you do it? When a user logs in? Thanks for the help!Dade
A quick solution is create two sets of users, one in Parse, one in Firebase. When you add a user to Parse, also add it to Firebase. You could also just forget that completely and use use Firebase for Authentication and leverage Parse just for the Push notifications. If you have not coded up an app in Parse yet, it's pretty darn good and worth the time to experiment - you could slap together a basic app in probably 20 minutes to see how they use Push Notifications.Orndorff
Using Firebase for authentication and leveraging Parse just for Push notifications is what I'm trying to do. Do you have any sample code or resources for how to that. I'm sure it's easy, I just haven't been able to figure it out! Thanks again @Jay!Dade
Parse has a snappy iOS Push Tutorial! Create a free parse account and download the code!Orndorff
Agree with @Orndorff on most points -- check the docs and experiment! Though I'd strongly suggest against client push: it's inherently insecure and very easy to exploit. Probably fine for a trial app, but not good for production. See here for more: blog.parse.com/learn/engineering/…Cida
D
1

Here's the answer I got from the Firebase team:

Firebase currently does not have push notification feature. You can use Firebase Queue and GCM to implement push notification in your app. Queues can be used in your Firebase app to organize workers or perform background work like generating thumbnails of images, filtering message contents and censoring data, or fanning data out to multiple locations in your Firebase database. Google Cloud Messaging (GCM) is a free service that enables developers to send messages between servers and client apps and it is available in both iOS and Android.

You can push an object with some data to the /queue/tasks location in your Firebase using any Firebase client or the REST API. Workers listening at that location will automatically pick up and process the job. From that, your workers can make a GCM push notification.

(end of message from Firebase team)

~~~~~~~~~

Here's my analysis:

It seems like there are a few solutions, but the two best ones are:

1) Use FirebaseQueue with Google Cloud Messaging.

2) Leverage the Push Notification functionality in Parse within the Firebase app.

I'm not sure which is better. Parse seems more proven, but Firebase Queue is more-easily integrated into the app (ie. it's nice have everything on Firebase and not having to set up a Parse app)

Anyways, I hope this thread helps out other people!

Dade answered 9/1, 2016 at 1:32 Comment(2)
Three things: If my answer helped you, please accept it! Don't post an answer to your own question - edit your question with additional info or edit the answer, or post a comment. You really need to go through the Parse Notifications app example. It's super easy and can be integrated into your app with very little time and effort. Glad we could help!Orndorff
Thanks @Orndorff for the help! I'm new to stackoverflow and don't fully understand the decorum. I just liked your post, but I'm going to leave the second answer, just because it often helps me to read through many different answers instead of just one. But again, thanks for your help. I've gone through the Parse example, and it was very helpful!Dade
W
1

Just realized that they've come out this:

Batch

Whitley answered 4/4, 2016 at 1:54 Comment(0)
P
1

Firebase now has Notifications inbuilt. https://firebase.google.com/docs/notifications/

Pollack answered 25/5, 2016 at 13:34 Comment(0)
T
0

I had the same problem and managed to figure out a solution a while back. I have detailed my solution in the following posts https://mcmap.net/q/1007456/-firebase-listener-when-app-is-in-the-background and https://mcmap.net/q/1007457/-keep-a-firebase-listener-in-memory-when-the-app-is-in-background

You have to create a firebase data service class and use a shared instance to hold the observers in memory when the app goes into background. From there it is just a matter doing what you wish.

Tamelatameless answered 3/8, 2017 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.