Search code examples
firebaseionic2firebase-cloud-messagingfirebase-notifications

Does Ionic 2 support private & public Firebase notifications?


I'm thinking to work on firebase notifications in the last few days but I want to some answers for this few questions:

  1. Does Ionic2 support firebase notifications ?

  2. Will notification show in the top of screen when my application closed or it should be work in the background ?

  3. Is firebase notification sent on time or it may take long time ?

  4. If I assumed Ionic 2 can send private notifications (to my device only), so can I send public notification for all application users ?

If the answer of all questions "yes", wish you give me any useful links that may help me (if you have a time)


Solution

    1. Yes it does, and it works fine with FCM (Firebase Cloud Messaging, aka GCM - Google Cloud Messaging). It supports subscribing to topics and device-to-device notification via HTTP client. The topics subscriptions and device-to-device both require FCM plugin.

    2. Yes, they'll appear on top of your device screen as any push notification, you'll just need to code how it'll behave after receiving it, like execute something if the notification is tapped, or do something if it's received and the app is already open (foreground), it's all up to you.

    3. It's sent on time, i've never had delay problems, the longer it took to send the notification and i receive in my device was 10 seconds. But as far as i know it "stores" your notification for 24 hours, so if the servers go down or something happen the notification has a life time of 24 hours to be sent.

    4. You can, as said in first answer, subscribe your users to topics. Let's say you want a topic to sent message so all users can receive, you can have an all topic, or have one only for logged users, one only for users who bought products, you can even get all users tokens and send one by one, but it's much better having them subscribe to topics.

      Topics notifications can be sent via the Firebase project console. Device-to-device is sent by your app code.

      To send device-to-device you'll need a token, it's provided by the FCM plugin (link above) and you'll need to store this token somewhere, like in your user node on Firebase. I usualy use the user device ID provided by the Device plugin to have his token, since the user can have multiple devices and log in all then, this'll prevent token overriding.

    I don't know good tutorials about configuring FCM with Firebase, if i find something i'll edit the question and add it for you, but stick to the ionic native link and the FCM plugin github page.

    Hope this helps.