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

Background push in Android and IOS #557

Open
VisualMafia opened this issue May 24, 2022 · 35 comments
Open

Background push in Android and IOS #557

VisualMafia opened this issue May 24, 2022 · 35 comments

Comments

@VisualMafia
Copy link

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

@jkasten2
Copy link
Member

jkasten2 commented May 24, 2022

@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.

@VisualMafia
Copy link
Author

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?

@jkasten2
Copy link
Member

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.

@VisualMafia
Copy link
Author

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.

@apoorvpandey0
Copy link

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.

@ArslanAsghar123
Copy link

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

@davetebonfire0302
Copy link

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?

@ArslanAsghar123
Copy link

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

@hatemragab
Copy link

Any updates?

@mu-dawood
Copy link

any update

@ArslanAsghar123
Copy link

ArslanAsghar123 commented Jan 31, 2023

@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}");


});

@mu-dawood
Copy link

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

@obrunofontana
Copy link

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?

@mu-dawood
Copy link

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

@jhandaya
Copy link

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

@apoorvpandey0
Copy link

apoorvpandey0 commented Feb 28, 2023

Anyone who understands native code for this please help, Onesignal team isn't helping here.
Also if anyone can understand this fix code #464

@baimamboukar
Copy link

Has someone succeded to display notifications in background ?

@viniciusoliverrs
Copy link

Any workarounds available to receive notifications in the background?

@cdmunoz
Copy link

cdmunoz commented Jul 21, 2023

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?)

@viniciusoliverrs
Copy link

viniciusoliverrs commented Jul 21, 2023 via email

@cdmunoz
Copy link

cdmunoz commented Jul 21, 2023

@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?

@Paroca72
Copy link

Paroca72 commented Aug 7, 2023

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

@cdmunoz
Copy link

cdmunoz commented Aug 8, 2023

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

@chellongCoder
Copy link

any update?

@bogdannedelcu
Copy link

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!!!

@femiWiseki
Copy link

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

@StatTark
Copy link

StatTark commented Apr 1, 2024

Any updates?

@Gonn01
Copy link

Gonn01 commented May 20, 2024

Any update?

@femiWiseki
Copy link

femiWiseki commented May 27, 2024 via email

@DevelopmentDan
Copy link

@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.

@dotola
Copy link

dotola commented Jul 31, 2024

..

@apoorvpandey0
Copy link

This issue has been solved in latest version 5.x.x

@bogdannedelcu
Copy link

bogdannedelcu commented Aug 1, 2024 via email

@Gonn01
Copy link

Gonn01 commented Aug 1, 2024

Im receiving the background notification but there is a way to handle it?

@dotola
Copy link

dotola commented Aug 1, 2024

when clicked the notification can't open the app

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