7

I'm using firebase-admin on nodejs to send push notifications to users: https://firebase.google.com/docs/admin/setup

I'm using firebase_messaging on flutter: https://pub.dev/packages/firebase_messaging

I'm trying to send a push notification with the highest priority on both android and ios.

firebase.messaging(firebaseApp).send({
    token,
    notification,
    android: { priority: 'high' },
    apns: { headers: { 'apns-priority': '10' }, payload: { aps: { sound: 'default' } } },
    data
}

On my development devices it works like a charm both when the app is in the background and when it's terminated.

I'm receiving push notifications that visibly pop and make a sound 100% of the time, on both android and ios.

The issue is on other devices -

If the app is in the background, I can sometimes see an actual push notification visibly pop, and make a sound as it should. Sometimes not.

If the app is terminated, a push notification is received - but it doesn't visibly pop nor make a sound, I can only see it if I scroll down the menu from the top of the screen, it's listed as a received push notification. Sometimes the notification is not receieved at all.

I tried to change the priority of notifications from my app to high on the actual device as well, but it didn't change anything.

My users keep complaining that they're not receiving push notifications - I'm guessing they either actually don't receieve them or simply don't see them since they're recieved silently as I described above.

I literally have no idea what's going on and why it doesn't work as it should on devices other than my own development devices.

Any ideas?

zkohi
  • 2,486
  • 1
  • 10
  • 20
Royi Bernthal
  • 882
  • 4
  • 17
  • 45

1 Answers1

4

There are two tags that need to be intact when we are sending push from firebase api

  1. priority
  2. android_channel_id

If android 7.0 or 8.0 above device do not receive the android_channel_id than it will not show notification and so always set default notification channel in the android manifest. we can check available tags in json request we are setting via node. from here

<meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="@string/default_notification_channel_id"/>

like this and make sure you create the notification channel at mobile end.

String CHANNEL_ID = "your_channel id";
String CHANNEL_DESCRIPTION = "Your description to show in settings";


NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_DESCRIPTION, NotificationManager.IMPORTANCE_HIGH);
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(channel);

If you see the flutter app logs it will show you some error like default channel not set in manifest or no channel found in notification.

make sure you put logs in your question to resolve this or contact me to resolve the issue.

Also make sure you read Optionally handle background messages section from here fcm flutter lib there they mentioned adding fcm in android folder.

Parth Dave
  • 2,096
  • 13
  • 20
  • Thanks for the answer. I was not aware of that, I'm surprised that the firebase_messaging flutter package didn't cover that if it's so important to ensure push notifications delivery. How do I create channels in flutter? It seems like your code example isn't from flutter, correct me if I'm wrong. I couldn't find such an option in the the firebase_messaging flutter package. Also, it seems like that might cover android, what about ios? Logs - since this doesn't happens on my dev devices, is there any way I can get logs from other devices? – Royi Bernthal May 26 '20 at 20:24
  • I tried, it didn't change anything. I added the default channel id, plus followed the following to add channels in flutter: https://stackoverflow.com/questions/57783319/how-to-add-android-notification-channel-id-for-flutter-app-to-fix-notification-w – Royi Bernthal May 27 '20 at 13:55
  • you need to add this things in android code itself flutter code I think so not adding default channel id yet. sorry I have not tried yet about the channel I always found my self wander around the android code itself. but try this answer https://stackoverflow.com/a/62026611/4029614 I think that might work and also send same notification channel id from node – Parth Dave May 27 '20 at 19:37
  • I don't really seem to think that other than importance high there's anything that apns will block your notification to receive but apns rules: 10–Send the push message immediately. Notifications with this priority must trigger an alert.... It is an error to use this priority for a push notification that contains only the content-available key. 5—Send the push message at a time that takes into account power considerations for the device. They are throttled, and in some cases are not delivered. If you omit this header, the APNs server sets the priority to 10. – Parth Dave May 27 '20 at 19:43
  • so no need to set that importance or sound for ios, I guess ios will automatically play the sound itself. no need to specify on your end. – Parth Dave May 27 '20 at 19:43
  • You linked to the same topic I mentioned, that's exactly how I set my channells. I of course send the corresponding channel id via node as well. On IOS I actually must pass a sound for some reason or no sound will be played when the notification arrives. (I'm passing 'default' in node) To android manifest I added this: I'm guessing the actual value doesn't matter? Got any idea how we can further tackle this issue? – Royi Bernthal May 28 '20 at 08:57
  • yes that value matters android:value="default" it indicates channels in android if none channel id passed from fcm and when you declare that channel you also need to use same name to init channel for android before sending push. might be on app-level. – Parth Dave May 28 '20 at 09:11
  • so assuming I create in flutter a corresponding channel name "default", it's okay that I set android:value="default", right? – Royi Bernthal May 28 '20 at 10:58
  • The problem is that IOS users complained too about not receiving notifications. Perhaps we're focused on the wrong thing? Are there any other solutions we can try? – Royi Bernthal May 28 '20 at 11:02
  • The android device I'm checking on which doesn't receive notifications is Redmi Note 3. I'm not even sure how I can debug this in development debug mode if the problem is that the notifications are not received while the app is terminated. – Royi Bernthal May 28 '20 at 11:08
  • make sure Redmi devices have turned on background services, from security apps. as background services has been blocked by the mobile custom os. – Parth Dave May 28 '20 at 14:07
  • Background services are completely unrestricted, plus the device keeps getting notifications from other apps without any problems. – Royi Bernthal May 28 '20 at 18:02
  • Regarding your last edit - I believe that "Optionally handle background messages" refers to executing custom code when receiving a push notification while in the background, and is not required to actually display a push notification. Am I wrong? – Royi Bernthal May 29 '20 at 01:43
  • If you add data tag then yes, as firebase just checks for notification tag data not custom data read that also also i think we need to move things in chat as this is going too long conversation on the thread – Parth Dave May 29 '20 at 06:58
  • Would you like to continue this in email or skype? If you manage to solve this I would in this way or another award you the bounty, if the fact that it's about to expire is an issue. – Royi Bernthal May 31 '20 at 00:59