Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onNotification not working on iOS 9 #17

Closed
mparpaillon opened this issue Aug 28, 2017 · 9 comments
Closed

onNotification not working on iOS 9 #17

mparpaillon opened this issue Aug 28, 2017 · 9 comments

Comments

@mparpaillon
Copy link

Hi,

The plugin works great on Android but I don't manage to make it work on iOS. I tried sendToTopic and sendToDevice via Firebase admin but nothing worked.

My APN auth key is loaded on Firebase, I have enabled the Push capabilities via Xcode, I use a good certificate. But it doesn't work.

Is that a bug ?
Thanks

@mparpaillon
Copy link
Author

mparpaillon commented Aug 28, 2017

Ok my bad.

It works on iOS if I use "notification" and not "data".
Maybe I didn't understand ? Should I use notification key for iOS and data for Android ?

The thing is, if I use the "notification" key to send to a topic then Android will received the "notification" and not the "data"... Should I create separate topics for iOS and Android ?? Doesn't seem right...

@mparpaillon
Copy link
Author

It only works when the app is in background though... Nothing happens when app is in foreground. onNotification is never called

@andrehtissot
Copy link
Owner

Sry @mparpaillon,

I'm sorry, I currently have no device to test it on.
I updated the dependencies to use the newest code, so it may be working now. But I can't be sure.

@mparpaillon
Copy link
Author

mparpaillon commented Aug 28, 2017

Wow thanks a lot ! I'm checking this right now.

@mparpaillon
Copy link
Author

mparpaillon commented Aug 28, 2017

Ok it's definitely better. Here's the current state:

on iOS (9.3.5 in my case):

  • When app is in foreground: The data are received via onNotification. No dialog is shown though (I guess we have to create it ourselves if we want to)
  • When app is in background: A basic notification is shown (title and body from "notification" key) Nothing happens, until we tap the notification. Then app opens and this triggers the onNotification with all datas.
  • When app is closed: Same as in background

on Android:
It's the same as iOS except that:

  • A notifications is shown in foreground, background or when closed without any more code
  • We can't use "notification" key when sending the push notification since it overrides the "data" key with all the fancy stuff in it (custom icon, etc)

So I guess I need to send separately my push notifications because if I send one with "data" and "notification" I won't get my fancy notification on Android. I think I'll have to duplicate my topics for Android and iOS so I can send basic notification for iOS and fancy ones for Android.

I can close this now since I don't think it can get any better.
Thanks a looooot for your help and your reactivity ^^

@mparpaillon
Copy link
Author

mparpaillon commented Aug 29, 2017

@andrehtissot Since your plugin is creating the fancy notification by reading the "data" property, I guess that, somewhere in your code, you have to decide whether you create a basic notification via "notification" property or a fancy one by reading the "data" property. Or is that some magic on FCM plugin side ?

If that's the case maybe you could prioritize the fancy notification instead of the basic one ?

Maybe that's the place ?

if(remoteMessage.getNotification() != null
|| remoteMessage.getData() == null
|| remoteMessage.getData().get("notificationOptions") == null){
return; //does nothing
}
Map<String, String> originalData = remoteMessage.getData();
JSONObject options;
try {
options = new JSONObject(originalData.get("notificationOptions"));
} catch (JSONException e) {
return; //invalid json, all will be as default
}
new Manager(this).showNotification(new JSONObject(originalData), options);
(not a Android dev here, sorry ^^)

Also, some doc from Firebase: https://firebase.google.com/docs/cloud-messaging/concept-options

@mparpaillon mparpaillon reopened this Aug 29, 2017
@andrehtissot
Copy link
Owner

I'll take a look at it.

@andrehtissot
Copy link
Owner

andrehtissot commented Aug 29, 2017

The guide says that when the app is not in the foreground and there is both notification and data params, the app will not receive the data right away, and because of it the plugin "notification listener" won't be called, it won't be able to respond overriding the normal notification.
And sadly, when I tested, the guide was right.

So if the notification param is present, the plugin cannot work as intended. And only doing it when the app is in foreground looks weird to the user.

And sadly (again), according to the guide, the IOS only shows data-only notifications when the app is on, or gets to, the foreground.

Unfortunately, I don't see any answer other than sending only with the notification param to IOS devices and only with the data param to Android devices.

What do you think? Do you see another way?

@mparpaillon
Copy link
Author

Yup, sadly I've come to the same conclusion :(
Well I'll just concatenate the platform with the topics and slightly adapt my node script to send different push notifications to iOS and Android.

Thanks a lot for looking into it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants