Although there are already some discussion about handling notification in different situations, I'm still confused and couldn't make it work as expected.
So I did some testing on Android (6.0.1) and iOS (10.2). Here are the results for 4 cases.
1) On both Android and iOS, if the app is killed (not even in background), clicking on the notification launched the app but onNotificationOpen did not fire
2) When the app is in foreground and received a notification,
Android:
{
"tap":false,
"VARIABLE":"HELLO"
}
iOS:
{
"tap":false,
"gcm.notification.sound2":"default",
"google.c.a.e":"1",
"aps":{
"alert":{
"title":"TITLE",
"body":"BODY"
},
"sound":"default"
},
"gcm.n.e":"1",
"google.c.a.c_id":"2316898492889757467",
"google.c.a.udt":"0",
"gcm.message_id":"0:1483210416698465%27ea4cc727ea4cc7",
"google.c.a.ts":"1483210417",
"VARIABLE":"HELLO"
}
3) When the app is in background, clicking the notification launched the app and returned the below,
Android:
{
"google.sent_time":1483211347228,
"VARIABLE":"HELLO",
"from":"...",
"google.message_id":"0:1483209955103341%27ea4cc727ea4cc7",
"collapse_key":"..."
}
iOS:
{
"tap":true,
"gcm.notification.sound2":"default",
"google.c.a.e":"1",
"aps":{
"alert":{
"title":"TITLE",
"body":"BODY"
},
"sound":"default"
},
"gcm.n.e":"1",
"google.c.a.c_id":"8883332060820027786",
"google.c.a.udt":"0",
"gcm.message_id":"0:1483210505355447%27ea4cc727ea4cc7",
"google.c.a.ts":"1483210505",
"VARIABLE":"HELLO"
}
4) When the app is in foreground, clicking the notification (received before opening the app) returned the below,
Android:
{
"google.sent_time":1483211381401,
"VARIABLE":"HELLO",
"from":"...",
"google.message_id":"0:1483209955103341%27ea4cc727ea4cc7",
"collapse_key":"..."
}
iOS:
{
"tap":false,
"gcm.notification.sound2":"default",
"google.c.a.e":"1",
"aps":{
"alert":{
"title":"TITLE",
"body":"BODY"
},
"sound":"default"
},
"gcm.n.e":"1",
"google.c.a.c_id":"8182440151627446538",
"google.c.a.udt":"0",
"gcm.message_id":"0:1483210574475044%27ea4cc727ea4cc7",
"google.c.a.ts":"1483210574",
"VARIABLE":"HELLO"
}
Conclusion (unexpected results):
tap: trueI'm not sure how to handle notifications on iOS and Android natively.
I think it's fine to separately handle receiving notifications when the app is in foreground.
But I expect whenever the user clicks on a notification in the tray, it should behave the same as if the app was in background.
Any advise?
+1 when application is in background and click on the notification it doesn't trigger the callback. It did trigger it once or twice when switched to another state, but can't replicate anymore. (Tested on android 6)
+1 when the app is not in background (not launched), click on the notification opening the app but onNotificationOpen isn't triggered.
+1 for exactly the same behavior on Android ( especially no onNotificationOpen triggered when the app isnt launch )
Have anyone tried and made it work when the app is not launched on iOS or Android?
Wonder if it was implemented incorrectly on our sides.
+1 Receiving a notification while the app is not in background (not launched) for Android.
Additionally it seems like once this flow happens, the onNotificationOpen trigger never happens again during the app session, and a queue of incoming messages gets built up.
@chanphillip Have you tried manually setting the callback after getting a notification when the app is closed?
The flow:
1) App closed, send notification
2) Open app via the notification
3) Send a few more notifications; do they trigger the callback? (ours do not)
3) While the app is open in foreground, use Chrome (must have USB debugging on) to set the callback again window.FirebasePlugin.onNotificationOpen(a => console.log(a));
4) Fire another notification, notice that it should trigger the new callback
6) Open one of the old notifications you sent before. (From the notification bar) Does it trigger the callback multiple times?
@jfurfaro with the problem you mentioned for step 1-3, I guess you did not call onNotificationOpen on device resume? You need to call it on both device ready and resume.
Anyways, so far from the discussion in issue #108, we can confirm onNotificationOpen did not fire by tapping the notification when the app is not yet launched.
I'm closing this issue and continue discussion there.
Most helpful comment
+1 Receiving a notification while the app is not in background (not launched) for Android.
Additionally it seems like once this flow happens, the
onNotificationOpentrigger never happens again during the app session, and a queue of incoming messages gets built up.