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

Handling notification when app's in foreground - local notification? #1081

Closed
blueberry6401 opened this issue Oct 31, 2020 · 4 comments
Closed

Comments

@blueberry6401
Copy link

blueberry6401 commented Oct 31, 2020

Description:
Hi, considering this situation: I have some notifications pushed to the app, but one of them I want to handle it manually if app's in foreground. The other notifications are always show no matter what.
So I set inFocusDisplaying(None) and listen to 'received' event. Now I'm able to handle that notification manually, but how do I continue push the other notifications locally? Does react-native-onesignal support this or I have to use another library to do it?

@rgomezp
Copy link
Contributor

rgomezp commented Nov 1, 2020

Howdy,
Thanks for the question. You're in luck. This functionality was recently added to this SDK and is currently in the major release beta. With the new version, you will be able to dynamically decide to show or silence notifications based on whether the app is in the foreground as well as on other things like additional data values and more.

Take a look at this issue to learn more.

Enjoy!

@rgomezp rgomezp closed this as completed Nov 1, 2020
@empiteranga
Copy link

@rgomezp Is there any way to display a local notification when the app is in foreground android

@jkasten2
Copy link
Member

@empiteranga The SDK displays a push notification automatically, even when the app is in the foreground. If you do want to suppress this and display your own notification you can use OneSignal.Notifications.addEventListener('foregroundWillDisplay',(event) => {} ) to do this. More details here:
https://documentation.onesignal.com/docs/mobile-sdk#handling-notifications-before-theyre-presented-when-the-app-is-in-the-foreground

Due note if you use event.preventDefault(); and display your own local notification instead then you will need to handle the click event with your own code. The OneSignal SDK won't be able to receive the click event.

@maiznadeem
Copy link

@jkasten2 Hello, I have a question. How can I use foregroundWillDisplay listener for only certain notifications. Currently, If I add the listener, it'll not show any notification when app is open. However I only want selected notifications to not be displayed based on the notification payload.

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