FCM differences between Android and iOS about data messages - android

I'm using Firebase Cloud Messaging to send data payload and display notification in my Android and iOS apps. I'm integrating this in my iOS app and I'm in front of a curious thing.
Short story:
My notification server only send data messages (I mean JSON messages containing "data" field and with no "notification" field). In my Android app this is not a problem because I receive the message even if my app is in background in my Service implementation and I manually build a notification that I display. But in iOS case, how can I receive message when my app is in background to do the same? I mean if I add a "notification" field to my request I see the notification pop on my screen (when app is in background) and I can get data (located in the "data" field) after a click when my app is in foreground.
But can I have data when my app is in the background to manually display a notification?
Important precision:
The content of the displayed notification should be built app side and not server side because the server doesn't have enough informations, this is why I can't send the "notification" field in my payload message.
Thanks
EDIT: I solve (in part) this problem using this link. Shortly, I enabled both Background fetch and Remote notifications under Background Modes (and added content_available : true in the payload). Then I can process data received in didReceiveRemoteNotification: But now it still one thing: how make it works when my app is killed?
EDIT 2: I found something that could be the thing : that. Modifying the payload of a remote notification implies to handle incoming notifications before there are displayed. I'll try.
EDIT 3: Firebase doesn't support the mutable-content key required to make my solution found at EDIT 2 working. Discussion about that is here. So... Any idea?

I do not think it is possible to trigger "stock" notification on iOS from code the same way you do on Android using NotificationBuilder.
The only option available is to use hybrid messages with both notification and data payloads.
Check their doc for more information on hybrid messages.

On 16/02/14, Firebase added compliance with the "mutable-content" key. So that solved my problem and, I think, many people's problems.
Personal thinking:
I consider that 6 months late for this feature is really too much. I hope that future releases'll be up to date with iOS (as well as Android) releases.

Related

Firebase: Making multi-lang notifications

My case is the following: a user do something, then my Firebase script in Functions should notify his friends, but it don't know what lang set up for the app of certain friend.
If the Android app in foreground, there is no problem, I simply should send some json in notification payload and then parse it in onMessageReceived using current lang values. But I can't do the same, when the app in background or closed. So it sounds like I have to build multi-lang notifications at the backend, am I right? Any suggestions appreciated.
Searching for hours, I had found pretty good answer. You don't have to store lang constants in backend scripts, because you can manage notification's data even if your app in background or even closed. You just should clear notification field of notification payload. See full answer.

Firebase Cloud messaging no sound/vibration

I'm using firebase to send notifications to my app(iOS and Android).
I'm not keen on using the data fields to send my notifications because for iOS didReceiveRemoteNotification doesn't get called when user has force quit the app.
I've tried setting "sound" to all sorts of things including default and null but I'm not getting any sounds/vibrations on either devices.
Thanks.
There was just a minor issue. I was placing the sound in root of json payload. While, it had to be inside the notification object. Firebase should really have a number of example payloads in their documentation.
You can refer firebase document, table 2a
Should put sound filed into notification payload, then it should work

Push notification for XMPP Chat App for offline users in Group

Everyone....!!
Greetings..!!
I am working on XMPP based Chat app . I have used XMPPFramework by Robbie Hanson https://github.com/robbiehanson/XMPPFramework
i have used OpenFire as XMPP Server
I am facing problem to get Push Notification for Group Chat when user is offline.
Currently I am able to get Push Notification for One to One Chat when user is offline . (For this I have created a PHP WebService which fetches the information from ofOffline Table every 60 sec)
But As there are no Offline messages Tables for Group Chat.
Can anyone suggest me How can I get push notification to group when user is offline in group
I need to manage this from Both Android n iOS Chat App
for Android i am using
https://github.com/siacs/Conversations
Look into ejabberd_mod_offline_post
First config the Room must be a Member-Only room, and add all users as members right after you created it, so that be able to get a total.
Add above model into ejabberd models.
Implement a Callback Service to handle the callback post.
The idea is when User go offline
In one-to-one case, offline_message_hook will be raised
In MUC case, muc_filter_message will be raised, and any one not Presence-Available is offline.
The best example would be AMP implementation in the Tigase. It is based on a MessageAmp plugin and AMP component.
The MessageAmp plugin intercepts messages. If it detects that the user is not logged in, it forwards the message to AMP component to store it in an offline storage. In your case, you could have your own Message plugin which, if it detects that the user is offline, could forward the message to your Push component (iOS push or Android push, SMS push or something else).
And all the logic responsible for actual pushing notification to the device should be implemented in that component.
Try checking this MUC - Light and use the mod_zeropush module to modify a bit to handle single and group push from the muc-light.
Its more like whats app , although you may not achieve 100% results as you expect but less complex than the tradition XEP-0045.

Phonegap PushPlugin with a badge number and grouping feature

I have used pushPlugin to recieve push notification in my phonegap android application. Everything is working correctly. Only issue is when multiple messages are present in the notification bar, the last message overrides the previous message. I would like to group all the messages under the app as whatsApp does.
I tried adding notId parameter and setting it to random number from my server side code. Doing this actually displays multiple notifications but does not group then.
I would also like to know how to add badge number to my app. Basically a number which will tell the user that so many number of notifications are come. As it is in whatsApp (ex. 2 messages received). I have added this plugin to handle that, but I am not sure whether it has to be done in phonegap or will i have to modify java code (plugin) to achieve this.
I know this topic is addressed previously here but there is no answer to it. hence i have raised a new question. Any help would be appreciated.
I do think (although I totally am not sure) that WhatsApp doesn't actually show separate notifications, instead it concatenates the non-read messages on server before sending just one new notification that overwrites the current as you said. For example, if you initially have one message not read causing this notification
WhatsApp
Hey dude!
and then you receive another message, the notification sent is
WhatsApp
2 new messages from 2 contacts
or if the sender is the same contact
WhatsApp
Hey dude!\n
What is up?
You could use the pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);if you only needed iOS support but as it doesn't support the Android for that feature you need to use something else and that plugin you mentioned looks good for it. Seems like it is quite easy to use like this (after it is installed)
cordova.plugins.notification.badge.set(3);

What should the payload be for Android push notifications (GCM)

From my understanding of the GCM documentation you basically send whatever data you want as the data field. Then the client receives it and is responsible for handling it and displaying it. Is this wrong? What if like on iOS I just wanted to send a bit of text and have it display? Is there a standard key to use or anything? I'm pretty certain I've been through all the documentation I can find and don't see anything like this.
No, you're right. There are no standard keys like in iOS, it's all up to you seeing as you're the one responsible for the notification management.
Basically, in your BroadcastReceiver you should write the code for displaying a Notification in the status bar. Just parse your JSONObject from the recieved message and show whichever piece of text you may have set.

Categories

Resources