3

I was previously using parse for sending push notifications but now we are required to switch to other service provider. I am thinking of using firebase as my only requirement is sending push notifications on IOS and Android, and firebase seems to be close to what my requirements are.

I was searching for any facility provided by firebase to manage the user's data as in their device ids against the bundles they are entitled to. So, When i have to broadcast notifications, will firebase be retrieving appropriate bundles based on userid (or something like that) and vice versa (as parse was doing)? or do i need to manage this data and pick up appropriate device id before sending notifications?

Please help

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Sanket03
  • 41
  • 3

1 Answers1

1

All you really need on your server is your server API key and an appropriate InstanceID (generated by each device to address it individually). You -do- need to store the InstanceID if you want to tailor notifications to specific devices but there is also a mechanism to send segment and topic notifications that does not require you to store individual InstanceIDs.

For FCM you just make a HTTP POST request to their API endpoint, supplying your Server API key in the Authorization Header, and the InstanceID (Token); notification title; notification text; and any additional parameters in the request body.

Easy enough to test with Postman or FireBase console and they also have Node.js and Java libraries you can use on your server. It's backwards compatible with GCM and Amazon SNS so you can use that too should you wish.

For Android you just make a few small updates to your gradle build configuration, include the google-services.json file you download from google for your app/s and extend a few classes like FirebaseInstanceIdService and FirebaseMessagingService.

Note: If you're using Dagger2 for Dependency Injection on Android there is a small incompatibility that is easily fixed by following these instructions.

Community
  • 1
  • 1
Nathan
  • 2,617
  • 1
  • 19
  • 27
  • Thanks Nathan.. My question was who has to manage the registartion_ids? Lets say i have 1000 users and if i need to send notification to Tom, am i needed to retreived the registation id or firebase would be able to do that if i provide userid=Tom (or something simillar) ? – Sanket03 Jul 28 '16 at 11:21
  • In short you have to manage the relationship between users and their device tokens. Things like topics and device groups do make this a simple process. – Arthur Thompson Jul 29 '16 at 00:14
  • 2
    You should send the InstanceID (Token) to your server every time it changes. (see https://firebase.google.com/docs/notifications/android/console-device#access_the_registration_token) The easiest way I've found to do this is to save the token locally in shared preferences on update (see http://stackoverflow.com/questions/37454501/firebase-fcm-force-ontokenrefresh-to-be-called) and set an additional TokenChanged flag in SharedPreferences. Your app can check this flag on launch and persist the InstanceID to your API (with something like Retrofit) as appropriate. – Nathan Jul 29 '16 at 03:03