OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

Background push in Android and IOS

Open VisualMafia opened this issue 3 years ago • 35 comments
trafficstars

I switched to the latest version (3.3.0) and there are fewer features than before. Once pushes worked in the background in IOS, then after new versions they stopped working. Now even in Android it is impossible to receive a push in the background, as it was in setNotificationReceivedHandler. Are you planning to return at least for Android or not to wait for this important feature? Thanks

VisualMafia avatar May 24 '22 14:05 VisualMafia

@VisualMafia Thanks for your question. The setNotificationReceivedHandler was replaced with setNotificationWillShowInForegroundHandler. As the name notes, this will only fire when your app is in the foreground and let's you decide if you want to show notification to the user.

The original setNotificationReceivedHandler from 2.x.x had a number of limitations that does not allow it to fire in all cases in the background so it was removed.

What is the use case for the setNotificationReceivedHandler you have? I would like to know how we can support this.

jkasten2 avatar May 24 '22 18:05 jkasten2

Thanks for the answer, yes, we use the setNotificationWillShowInForegroundHandler method, but this is not enough. Previously, setNotificationReceivedHandler covered our needs (in Android). Every push is important to us, and if only setNotificationWillShowInForegroundHandler, then all messages are lost when the application is in the background. Can we read all the pushes that have arrived when the application returns from the background?

VisualMafia avatar May 24 '22 18:05 VisualMafia

Can we read all the pushes that have arrived when the application returns from the background?

Thanks for the details, that is good information to have. Do you only need the notifications are currently showing (not interacted with) or all notifications received?

The OneSIgnal native SDK (that this Flutter repo uses) does still include options for these, however it requires you to write native code: https://documentation.onesignal.com/docs/service-extensions

One if the major limitations of setNotificationReceivedHandler in the old SDK is that if the User swiped away your app it would no longer fire. This is due to iOS's limitations, they require you to add a Notification Service Extension to account for this, however it has to be written in Swift or Objective-C.

jkasten2 avatar May 27 '22 00:05 jkasten2

Thanks for the answer. But, in Android it worked fine before. It is important for us to see the data that came in the push when the application is active or in the background. Now this only works when the app is active.

VisualMafia avatar May 27 '22 20:05 VisualMafia

Thanks for the answer. But, in Android it worked fine before. It is important for us to see the data that came in the push when the application is active or in the background. Now this only works when the app is active.

Exactly, there are some PR's also fixing this but the team is not taking note of this issue.

apoorvpandey0 avatar Jun 18 '22 11:06 apoorvpandey0

I read docs for background data notification and add a service file too but I still can’t make any progress

ArslanAsghar123 avatar Sep 12 '22 10:09 ArslanAsghar123

I read docs for background data notification and add a service file too but I still can’t make any progress

Have you found a solution to receive notification while app is in background?

davetebonfire0302 avatar Nov 15 '22 04:11 davetebonfire0302

I read docs for background data notification and add a service file too but I still can’t make any progress

Have you found a solution to receive notification while app is in background?

one signal is already capable of sending a notification when the app is in the background but I can’t find anything to trigger any specific function when a notification arrives in-app background state

ArslanAsghar123 avatar Jan 03 '23 10:01 ArslanAsghar123

Any updates?

hatemragab avatar Jan 23 '23 19:01 hatemragab

any update

mu-dawood avatar Jan 26 '23 10:01 mu-dawood

@mo-ah-dawood

any update

I update my code like this whenever a user using the app and a notification arrives, I trigger the foreground notification function and run the function without showing any notification.

  OneSignal.shared.setNotificationWillShowInForegroundHandler((event) {
   // Will be called whenever a notification is received in foreground
   // Display Notification, pass null param for not displaying the notification when notification TYPE from server changes

  final notification = event.notification;

  if (notification.additionalData!["type"] == "NOTIFICATION_TEXT") {
    event.complete(notification);
  } else {
    getUpdatedData(context); //Function
    event.complete(null);
  }
  print("this is notification title: ${notification.title}");
  print("this is notification body:  ${notification.body}");
  print(
      "this is notification additional data: ${notification.additionalData}");


});

ArslanAsghar123 avatar Jan 31 '23 11:01 ArslanAsghar123

I know how to handle my data in foreground but what about the notifications that comes while the app is in background

mu-dawood avatar Feb 17 '23 14:02 mu-dawood

I know how to handle my data in foreground but what about the notifications that comes while the app is in background

I'm facing the same problem, I haven't found a way yet to handle notifications that are received in the background... any help?

obrunofontana avatar Feb 22 '23 20:02 obrunofontana

no, currently I'm loading all my APIs after app resumed from background I know its very heavy for my app but it was my only solution

mu-dawood avatar Feb 22 '23 21:02 mu-dawood

I am facing the same problem, I am able to receive the notification, but there is no way to handle it while my app is still in background

jhandaya avatar Feb 23 '23 15:02 jhandaya

Anyone who understands native code for this please help, Onesignal team isn't helping here. Also if anyone can understand this fix code https://github.com/OneSignal/OneSignal-Flutter-SDK/pull/464

apoorvpandey0 avatar Feb 28 '23 14:02 apoorvpandey0

Has someone succeded to display notifications in background ?

baimamboukar avatar Jun 13 '23 14:06 baimamboukar

Any workarounds available to receive notifications in the background?

viniciusoliverrs avatar Jul 12 '23 00:07 viniciusoliverrs

Folks, I'm here looking for a solution to the same problem ... is there a way to handle push notification received when in background? (or should we change and not using One Signal?)

cdmunoz avatar Jul 21 '23 17:07 cdmunoz

The solution I found was to create an event channel to handle messages in the background

Em sex., 21 de jul. de 2023 às 14:38, Carlos Daniel < @.***> escreveu:

Folks, I'm here looking for a solution to the same problem ... is there a way to handle push notification received when in background? (or should we change and not using One Signal?)

— Reply to this email directly, view it on GitHub https://github.com/OneSignal/OneSignal-Flutter-SDK/issues/557#issuecomment-1646037803, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHL3RC53BJMN7JZN2U2UXSDXRK5CLANCNFSM5WZZJ4TQ . You are receiving this because you commented.Message ID: @.***>

viniciusoliverrs avatar Jul 21 '23 19:07 viniciusoliverrs

@viniciusoliverrs thanks for letting us know ... although if I'm understanding well, did you create a new package (channel) not public in which you did your own background push notifications handle? If so and possible, could you share some gist or something?

cdmunoz avatar Jul 21 '23 20:07 cdmunoz

Some solution to this issue? This is a huge limitation to using OneSignal in any projects.

Paroca72 avatar Aug 07 '23 04:08 Paroca72

It is indeed ... no workarounds from my side, so far

cdmunoz avatar Aug 08 '23 13:08 cdmunoz

any update?

chellongCoder avatar Sep 13 '23 04:09 chellongCoder

The effect of this issue is that if the user sees the notification but chooses to open the app instead (app being in background) we are not informed in the code that there was a notification actually. We loose the notification. And since we use one-signal integrated with MixPanel this is mandatory as custom cohorts are available only between these platforms, not in our backend.

HELP!!!

bogdannedelcu avatar Oct 10 '23 15:10 bogdannedelcu

Hi everyone, has anyone been able to implement push notifications in the background with Onesignal?

femiWiseki avatar Jan 23 '24 08:01 femiWiseki

Any updates?

StatTark avatar Apr 01 '24 10:04 StatTark

Any update?

Gonn01 avatar May 20 '24 14:05 Gonn01

On 2024-05-20 14:35, Gonn01 wrote:

Any update?

-- Reply to this email directly, view it on GitHub [1], or unsubscribe [2]. You are receiving this because you commented.Message ID: @.***>

Links:

[1] https://github.com/OneSignal/OneSignal-Flutter-SDK/issues/557#issuecomment-2120590946 [2] https://github.com/notifications/unsubscribe-auth/BCLZNDLTS3BTEKIG4ZZO733ZDIC45AVCNFSM5WZZJ4T2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMJSGA2TSMBZGQ3A I have fixed the issue that I had. Thanks for reaching out.

femiWiseki avatar May 27 '24 06:05 femiWiseki

@femiWiseki - if you managed to fix the issue, can you share with us how? We all need to be able to handle these notifications when the app is in the background. Thank you.

DevelopmentDan avatar Jul 03 '24 10:07 DevelopmentDan