Pushwoosh / pushwoosh-flutter

Pushwoosh Flutter Plugin
Other
8 stars 16 forks source link

Possibility to control if notifications will be presented while app is in foreground #45

Open matszafraniec opened 3 years ago

matszafraniec commented 3 years ago

Hello,

can you tell me if there is a possibility to control wherever notifications will be shown when app is in foreground?

I checked there is setShowForegroundAlert method, which disable alerts when app is in foreground and I can capture notification which comes in onPushReceived listener. But then, I have to use other packages to present notification (after in custom data payload I receive expected data).

I would like to ask if there is a possibility to make it with Pushwoosh package?

wfhm commented 3 years ago

Hey @matszafraniec

Could you please elaborate on this request? Do you want to show notifications when your app is in foreground only in particular places in the app (show notification alert on one page and do not show it on another one)? If so, do you think adding a method to create notifications from push payload combined with setShowForegroundAlert would work for you?

matszafraniec commented 3 years ago

@wfhm You've got the concept.

So setShowForegroundAlert() can be set to true and false multiple during app lifecycle?

There can be a logic in onPushReceived(payload) like that:

if app is in foreground and payload.contains == 'navigation' setShowForegroundAlert(false) <--- here notification will not be presented? else setShowForegroundAlert(true) <--- here notification will be presented?

wfhm commented 3 years ago

@matszafraniec

It can be done multiple times, but, in your case, it is not going to work - push payload is handled asynchronously, so there is a chance that notification will be generated/discarded before you change the state of the ShowForegroundAlert flag.

The obvious solution is to generate a notification manually after receiving a push payload from onPushReceived (for example, by creating a new public method in our SDK). However, this is not something we really want to add to Pushwoosh SDK, as it is designed to handle notifications under the hood, and creating such a method does not really fit into this concept.

Can you describe your usecase in a bit more detail so we could try finding a solution that will not require such changes in our SDK? If this information is something you do not want to publicly expose, you can submit a support ticket at our Help Center with a reference to this issue. What do you think?