Push Notificacions with Google Firebase Notifications

Back to How-to Discussions
An issue has been acknowledged in this thread and it is being tracked internally by the Fuse team.

Hi!!

Fuse Push Notifications in Android works with Google Firebase Notifications? I would appreciate a code example if is possible...

Thanks!!

Hello! As of November, Google is forcing all developers to use Firebase Cloud Messaging for all new apps. So we are unable to set up GCM and to our team this is a major inconvenience out of nowhere.

I believe a lot of new developers will be affected. Perhaps Fuse Team should look in to this as a priority for the Push module?

Firebase notifications it's possible. You just have to follow the actual tutorial https://www.fusetools.com/docs/fuse/pushnotifications/push. In the Step 2. (Only for Android), create your firebase project, go to the firebase console and copy/paste the sender id.

file

I'm still don't implement it in iOS but I suppose it is pretty straightforward.

Cheers!

Edit: I'm trying to implement and iOS. It's not "straightforward" x.x

Hi, Any progress with push notification Fuse + Firebase on android? does anyone has an example to share? cause until it works, no way to have push notifications on Fuse.

Luis Rodriguez wrote:

@itai.lwein: if you need push notifications on Android just follow Jesus Martinez advice

jesusmartinoza wrote:

Firebase notifications it's possible. You just have to follow the actual tutorial https://www.fusetools.com/docs/fuse/pushnotifications/push. In the Step 2. (Only for Android), create your firebase project, go to the firebase console and copy/paste the sender id.

push.on("receivedMessage", function(payload) {
    console.log("Recieved Push Notification: " + payload);
});

only shows output on console. Any way to show it on Android notification bar??. Don't know how to use after this...

@Tom, I am not 100% sure (I don't have an Android) but someone told me you have to use LocalNotify for it to appear no the Notification Bar (again, android only).

After adding it to your project (https://www.fusetools.com/docs/fuse/localnotifications/localnotify), give this a try and let me know what happens.

push.on("receivedMessage", function(payload) {
    console.log("Recieved Push Notification: " + payload);
    LocalNotify.now("Boom!", "Just like that", payload, true);
});

Ps. since I am not sure what I am doing maybe we should talk it over Slack? Add me: luisrodriguezld

Well, did all the settings and I run this:

{
  "RootNamespace":"",
  "Packages": [
    "Fuse",
    "Fuse.PushNotifications",
    "Fuse.LocalNotifications",
    "FuseJS"
  ],
  "Includes": [
    "*"
  ],
  "Android": {

    "GooglePlay": {
        "SenderID": "mySenderID"
    }
},
}

and:

<App>
	<JavaScript>
			var Observable = require("FuseJS/Observable");
			var Payload = Observable("-->Payload here<--");

	    var push = require("FuseJS/Push");
			var LocalNotify = require("FuseJS/LocalNotifications");
	    push.on("registrationSucceeded", function(regID) {
	        console.log("Reg Succeeded: " + regID);
	    });

	    push.on("error", function(reason) {
	        console.log("Reg Failed: " + reason);
	    });

	    push.on("receivedMessage", function(payload) {
	        console.log("Recieved Push Notification: " + payload);
					LocalNotify.now("Boom!", "Just like that", payload, true);
					Payload.value = payload;
	    });
			module.exports = {
  			Payload:Payload
			};

	</JavaScript>
	<StackPanel>
		<Text TextAlignment="Center" Value="Payload"/>
		<Text TextAlignment="Center" Value="{Payload}"/>
	</StackPanel>

</App>

manage to get connection confirmation from the Firebase server, but when I try to send a message from there notifications tool, nothings happens.

file

So i manage to push the message from firebase console by targeting on single device.
but if I choose target as user segment, push notification doesn't come at all. 
I have 3 device connected. I want to send push message on all device at once.
@itai.lewin, try sending push using single device.  FCM registration token is device token.

file

file

Same here, manage to make it work (kinda) only for single device (FCM registration token) it will force me to send for each connected device it's FCM registration token, then send to each of the separately. btw, it doesn't work on preview, only on build

Check this:

Notification messages are delivered to the notification tray when the app is in the background. For apps in the foreground, messages are handled by these callbacks:

didReceiveRemoteNotification: on iOS

onMessageReceived() on Android. The notification key in the data bundle contains the notification.

source: https://firebase.google.com/docs/cloud-messaging/concept-options

Maybe you need to convert the notification to an alert, I'm not sure, I'm new on this

Tom wrote:

Luis Rodriguez wrote:

@itai.lwein: if you need push notifications on Android just follow Jesus Martinez advice

jesusmartinoza wrote:

Firebase notifications it's possible. You just have to follow the actual tutorial https://www.fusetools.com/docs/fuse/pushnotifications/push. In the Step 2. (Only for Android), create your firebase project, go to the firebase console and copy/paste the sender id.

push.on("receivedMessage", function(payload) {
    console.log("Recieved Push Notification: " + payload);
});

only shows output on console. Any way to show it on Android notification bar??. Don't know how to use after this...

Im currently testing to find the smallest fix to a problem we do have with firebase messages. I'm going to brainsdump here so you folks know where we are and where we are going.

Where we were

Kinds of Message.

GCM had two kinds of messages notification messages and data messages. Notification messages are delivered to the notification tray when the app is inactive, data messages are delivered to the app (even when in the background or closed).

notification messages had this structure:

{
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
  "notification" : {
	"body" : "great match!",
	"title" : "Portugal vs. Denmark",
	"icon" : "myicon"
  }
}

data messages had this structure:

{
  "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
  "data" : {
	"Nick" : "Mario",
	"body" : "great match!",
	"Room" : "PortugalVSDenmark"
  },
}

See here for more details

Fuse provided the following behaviour:

  • if the app is in the background or closed we make a notification in the notification tray. We use data in the message to customize your notification (sound, title, body, etc)
  • if the app is in the foreground we deliver the message striaght to JS with nothing in the tray

This gave us behaviour on Android that matched iOS APNs, which we felt was valuable for app similicity.

The bit that we had an example for but totally failed to explain in the tutorials was that in order for this mechanism to work the message HAD to be a data message

We also had the data laid out in a daft way:

...
body: JSON.stringify({
	registration_ids: [regID],
	data: {
		notification: {
			alert: {
				title: 'Well would ya look at that!',
				body: 'Hello from some other app',
				icon: 'Foo.png'
			}
		},
		payload: 'anything you like'
	}
})
...

Where we are

The fact we do not handle notification messages properly is a real bug and one I am working on this week.

However from testing I can report that the data messages in the above format DO still work with Fuse.PushNotifications even if the app is in the background or is closed.

Where we are going

Naturally the notification message bug needs to be fixed (and will be). I also want to move away from our suboptimal notification layout and use something more appropriate. This is a breaking API change though so our release guidelines require us to deprecate the old stuff for a period of time first.

The question of data -v- notification messages may remain. By using data messages, we are able to do things that are not in the Firebase specification but that our customers have specifically asked for. One example of this is support for largeIcon in notifications, which is something Firebase do not yet support

Comments

Please shout below ! Note that we at Fuse won't be able to take the 'minimal viable product' on this library as we have customers using specific features today, however we will get something that works great with how Firebase works, provides a sensible cross-plat behaviour and gives folks time to migrate.

I hope this clears up a little, I'm happy to expand on any part.

Post Stats
  • 17
    replies
  • 3879
    views
  • 5
    users
Frequent Posters