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

onNotificationOpen called when app is in foreground for iOS #987

Closed
DevArenaCN opened this issue Jan 15, 2019 · 14 comments
Closed

onNotificationOpen called when app is in foreground for iOS #987

DevArenaCN opened this issue Jan 15, 2019 · 14 comments

Comments

@DevArenaCN
Copy link

Describe the bug
When app is running in the foreground, after receiving the notification, the onNotificationOpen function gets called immediately without the user tapping on the notification.

To Reproduce
Steps to reproduce the behavior:

  1. Run the app
  2. Send a notification when the app is running
  3. onNotificationOpen functions gets called.

Expected behavior
I would expect that this function only gets called when "opening" the notification, ie, tapping on the notification.

Plugin Version
2.0.5

Smartphone (please complete the following information):

  • OS: iOS 12.1.2
  • Version: Cordova iOS 4.5.5
@RameshkrishnanV
Copy link

Same issue. any fix for this? for me its triggering onnotificationOpen method twice.
Please help me!

@DevArenaCN
Copy link
Author

@RameshkrishnanV what I did was a hack way in my opinion, which is:

  1. change AppDelegate+FirebasePlugin.m line 183 from
    completionHandler(UNNotificationPresentationOptionAlert);
    to
    completionHandler(UNNotificationPresentationOptionNone); so it won't show the notification banner while app is in foreground.
  2. added event listener for pause and resume to determine if the app is in foreground, if it's not then do whatever needs to be done in onNotificationOpen, if not then handle it differently, in my case, do nothing.

@RameshkrishnanV
Copy link

Thanks @DevArenaCN. Let me try!

@DevArenaCN
Copy link
Author

@RameshkrishnanV good luck. But to me I don't think that's the way onPushNotification should be called since popping up the banner doesn't necessarily meant that the notification is opened.

@RameshkrishnanV
Copy link

yeah u r right! for me its happening only on ios.
Did u tried this way?
#913

@DevArenaCN
Copy link
Author

No I didn't. And granted I didn't test on Android because in my case the app is iOS only, so I'm not sure what the behavior is on Android. I just wanna see if this is intentional or it's a bug, to me it feels like a bug

@RameshkrishnanV
Copy link

@DevArenaCN Thanks its working. but for onNotificationOpen triggers twice, do u have any idea?

@DevArenaCN
Copy link
Author

DevArenaCN commented Jan 22, 2019

Hmmm I didn't see the event being triggered twice in my case, might wanna check your function for receiving the onNotificationOpen event.

@RameshkrishnanV
Copy link

@DevArenaCN I remember need to add id for notification so ios will handle it. do u know how to add notification id to the fcm payload? please help me in this.

@DevArenaCN
Copy link
Author

apns-collapse-id?

@Farmertjes
Copy link

Farmertjes commented Apr 3, 2019

@DevArenaCN My solution is (line 183 of AppDelegate+FirebasePlugin.m)

NSNumber *background = self.applicationInBackground;
    
if([background boolValue]) {
    completionHandler(UNNotificationPresentationOptionAlert);
} else {
    completionHandler(UNNotificationPresentationOptionNone);
}

This edit prevents the need to implement extra hacks in the app. Notifications will show in background, not in foreground.

@DevArenaCN
Copy link
Author

@Farmertjes Nice. I think with these two solutions it's safe to close this issue, but I do think this should be included in the plugin.

@snike1985
Copy link

@DevArenaCN You can check it in meta data:
window.FirebasePlugin.onNotificationOpen().subscribe((data) => {
if (data.tap) {
// user tapping on the notification
} else {
// app is running in the foreground
}
});

@hugoblanc
Copy link

@DevArenaCN You can check it in meta data:
window.FirebasePlugin.onNotificationOpen().subscribe((data) => {
if (data.tap) {
// user tapping on the notification
} else {
// app is running in the foreground
}
});

You're right but we can use tap only if we send Notification message and not Data message.

Which is problematic because it is less customizable: https://firebase.google.com/docs/cloud-messaging/concept-options

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

5 participants