Description:
Hi, I'm trying to figure out if it's possible to use the kOSSettingsKeyInFocusDisplayOption option to create proper push notification behavior for our messaging app. If you use any of the major messaging clients, the behavior is to show the push notification most of the time when the app is open, but then when the user is in a message thread that corresponds to the push notification, to just vibrate (and not show the push notification). So basically what I'm trying to accomplish is kOSSettingsKeyInFocusDisplayOption = 1 with a conditional.
Is there any way to implement this with the RN Client? Or do we need to do it at the native level? Doing it at the native level will be a pain though because the native thread doesn't have any good way to detect the currently focused screen.
Thanks in advance!
@scottmas this isn鈥檛 really achievable with our SDK. The only workaround would be to always set the inFocusDisplayType to NONE and display your own UI for notifications when applicable.
In short, there鈥檚 no way to change the display type a notification will be shown with _after_ it is received.
Okay that makes sense. To clarify, is this not possible even with the _native_ SDK's? I haven't dug into what's possible with those since our app is React Native, but I've assumed that it would be possible with enough mucking around.
@scottmas unfortunately that is correct, it's simply not possible with our SDK at the moment. The only workaround would be to _always_ use none as the display type and when you _do_ want to show a notification to a user, present your own UI for it.
This is a use case I have not previously given much thought to, but in retrospect, definitely should have, because I imagine for an app where you can send messages to people it makes sense to not want to show the notification if they are _in_ the thread. Thanks for bringing this up.
Correct me if I'm wrong, but I imagine the OneSignal SDK simply has a background process always listening for notifications which it then handles and displays to the end user. For instance, on Android this is done by overriding the onMessageReceived method.
If you guys are doing something like this on your native iOS/Android sdks, it seems like the most straightforward solution would be to provide a way in each of these SDKs for the developer to "inject" custom code in the handler, maybe by overriding one of your methods.
The above solution wouldn't help directly with doing this in RN, but at least it gets us closer.
@scottmas sorry for the slow response. The OneSignal SDK doesn't have a daemon that always runs in the background. But we _can_ fix this issue specifically. In the next week or so I plan to create a PR that will allow you to set the display type (ie. none, notification, etc.) for a notification before it gets shown.
It will be an iOS-SDK-only feature at first but I'll look into implementing it in Android as well soon after that.
That would be amazing Brad and is exactly what we need.
Any progress on this? Users are clamoring for it. I suppose we could use https://facebook.github.io/react-native/docs/pushnotificationios but that's only on ios
Hi @scottmas,
We haven't forgotten about you but with so many things to do, we have limited bandwidth on what issues we can resolve. Thank you for your patience! Thanks @Nightsd01 for your help on this
@scottmas I created a PR this weekend to add this feature.
https://github.com/OneSignal/OneSignal-iOS-SDK/pull/488
It is a native method however, and it needs to be done synchronously so that may complicate the RN integration. I will experiment to see how we can integrate this with RN.
Oooh exciting! This will be amazing.
Very exciting. I'm building a messaging app with the react-native-onesignal SDK for iOS/Android. It would be really great to be able to filter which messages display for exactly the reason you outlined above. Don't want to display notifications for the chatroom that's currently active. All other chatrooms should still show in-app notifications. This mirrors the behavior of WhatsApp and other messaging apps. Would be great to be able to do this with OneSignal 馃槃
I saw that the ios PR got merged. That's awesome! Any plans to implement the same functionality on Android? And/or expose the logic here in RN?
Yep! I will go ahead and create a PR for RN this weekend!
Do you anticipate being able to port the logic to Android as well? Or will you need to recruit help from within the organization?
We are moving enhancement/feature requests to our internal tracking tools. Issue still under consideration!!
Is there any progress to that feature request @rgomezp ?
Most helpful comment
Yep! I will go ahead and create a PR for RN this weekend!