Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Firebase push-notifications and FCM messages?

Heloo, I am building an app where I am using push notifications via Firebase Console. I want to know what is a difference between simply push-notification and cloud message? Is it that messages from cloud messaging are data messages(have key and value) and notifications are just text without key and value?Am I right?

like image 416
Atenica Avatar asked Jun 21 '16 14:06

Atenica


People also ask

What is difference between APNs and FCM?

APNs needs to be used for push messaging when an application is in the background. Hence, FCM uses APNs to deliver messages when the message contains user visible payload, e.g., body, sound etc. FCM also delivers via APNs when content available is set.

Can I send push notifications without FCM?

Without FCM, you'd need to build more than three notification systems. You'd need one each for iOS and Android, but then you'd also need to accommodate all the different types of browsers for the web application to deliver push notifications without a hitch.

What is FCM notification?

Firebase Cloud Messaging (FCM), formerly called Google Cloud Messaging (GCM), is a free cloud service from Google that allows app developers to send notifications and messages to users across a variety of platforms, including Android, iOS and web applications.


Video Answer


1 Answers

Firebase API has two types of messages, they call them:

  • notification
  • data

Explanation:

  1. notification - messages that goes directly to Android's Notification tray only if your application is in background/killed or gets delivered to onMessageReceived() method if your app is in foreground.

Sample:

{     "notification" : { "body" : "Hi"} } 
  1. data payload - Doesn't matter whether your application is in forground or background or killed, these messages will always be delivered to onMessageReceived() method.

Sample:

{     "data" : { "message" : "Hi", "whatever_key": "value"}  } 

Reference link

IMPORTANT : You can't send data payload messages from Firebase Console, Console only delivers notification message. However using API you can send both type of messages.

To send a data payload message you have to make a curl request:

HTTP POST Request

https://fcm.googleapis.com/fcm/send Content-Type:application/json Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA  { "data": {     "score": "5x1",     "time": "15:10"   },   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..." } 

You can get the server key (AIzaSyZ-1u...0GBYzPu7Udno5aA), from firebase console: Your project -> settings -> Project settings -> Cloud messaging -> Server Key

like image 87
Hisham Muneer Avatar answered Sep 18 '22 02:09

Hisham Muneer