Does firebase manage user data like device token,

2019-05-22 16:20发布

问题:

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

回答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.