OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
616 stars 213 forks source link

[Bug]: Notification still showing after calling event.preventDefault() #823

Open ilyasarafathemvigo opened 8 months ago

ilyasarafathemvigo commented 8 months ago

What happened?

onesignal_flutter 5.0.4 using this SDK version after calling this preventDefault() function still notification is showing

Steps to reproduce?

1. Add latest version of one signal flutter SDK (5.0.4) 
2. Send notification to a device.
3. Inside "addForegroundWillDisplayListener" listener call "event.preventDefault()" function to hide notification
4. Observe the result.

What did you expect to happen?

No need to show the particular notification after calling this function (preventDefault(+)

OneSignal Flutter SDK version

5.0.4

Which platform(s) are affected?

Relevant log output

No response

Code of Conduct

EM-Sabeel commented 8 months ago

@Nightsd01 @Jeasmine please go through the bug. I have the same issue

emawby commented 8 months ago

@ilyasarafathemvigo Thank you for reporting we are investigating

emawby commented 8 months ago

@ilyasarafathemvigo @EM-Sabeel I am not able to reproduce this issue, but I did notice some incorrect behavior when using "hot reload". It seemed that when I changed the behavior in the foreground display listener it wasn't being respected unless I did a full app reload instead of a hot reload. Are you not able to get preventDefault() to work even on full reloads? Also ensure that you aren't calling notification.display() after preventDefault()

ilyasarafathemvigo commented 8 months ago

Without hot reload am getting this error @emawby

nan-li commented 8 months ago

Hi @ilyasarafathemvigo, We haven't been able to reproduce, can you answer some additional questions?

  1. Is this consistently happening 100% of the time?
  2. Is this only happening in Android, not iOS?
  3. Can you share your setup code where you set addForegroundWillDisplayListener?
  4. Can you share logs when the device receives the notification? Thank you!
christofkost commented 7 months ago

I have the same problem when preventDefault is called after an async time gap. Is this a bug or intended behaviour?

nan-li commented 6 months ago

Hi @christofkost, You must call preventDefault by the time the callback returns. This is intended behavior as the listener cannot know about the async logic you plan to do later.

tarun824 commented 5 months ago

Same issue here, I want receive notification but not to show that notification so i must use event.preventDefault(); but even after this i am still getting notification . This is the code that i am using: OneSignal.Notifications.addForegroundWillDisplayListener((event) async { event.preventDefault(); final jsonrep = event.notification.jsonRepresentation(); final json = jsonDecode(jsonrep); print(json); //awesome_notifications await NotificationUtils().createLocalInstantNotification(json); }); @emawby , If you got some solution please inform @nan-li @christofkost @ilyasarafathemvigo @EM-Sabeel .