invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.84k stars 222 forks source link

Notification not showing when app is in killed state. #622

Closed ashishmangukiya closed 1 year ago

ashishmangukiya commented 1 year ago

Bug

Library version - @notifee/react-native - 7.3.0 react-native - 0.67.3

Issue -

I have added onBackgroundEvent() in index.js file at top but notification not showing when app is killed. notification is working when app is in background (not killed) or in running state.

Can anyone help on this? Am I missing any configuration to receive notification when app is killed?

quicksilverr commented 1 year ago

Hey, have you added the setBackgroundMessageHandler(), in the index.js file?

helenaford commented 1 year ago

can you provide more information about the use case, which platform (ios or android)? What's the payload of the remote notification? is it data-only?

ashishmangukiya commented 1 year ago

@quicksilverr Thank you for the comment.

targetSdkVersion = 33

But I am not using firebase here to receive push notification from server. just local scheduling using createTriggerNotification() method.

Case - 1) Added onBackgroundEvent() in index.js file as per notifee doc. 2) Scheduling a notification using createTriggerNotification() to receive after 10 mins. 3) App is closed now completely, after 10 mins I should receive a push notification but it's not happening. but if I open app after 10 mins then I get the same scheduled notification.

Not receiving if the app is closed.

Rc85 commented 1 year ago

@ashishmangukiya This might help

https://notifee.app/react-native/docs/android/background-restrictions

helenaford commented 1 year ago

Is this for android or iOS?

ashishmangukiya commented 1 year ago

@helenaford Now I am able to receive notifications even in killed state. the issue was bcz of background restriction

serveroid commented 1 year ago

https://notifee.app/react-native/docs/android/background-restrictions

How u fix it?

allisonadam81 commented 1 year ago

@serveroid I was having this problem when the app was killed. Only on Android. I couldn't get a push, and then when I opened the app all of my pushes would appear at the same time.

If I opened the phones settings and went to --

Settings --> Apps --> 'My App' --> App Battery Usage

then selected Unrestricted, things started working as expected. So Maybe check out the background restrictions and try to get your user to allow your app to run in the background.

Hope that helps.

Darren120 commented 1 year ago

@serveroid I was having this problem when the app was killed. Only on Android. I couldn't get a push, and then when I opened the app all of my pushes would appear at the same time.

If I opened the phones settings and went to --

Settings --> Apps --> 'My App' --> App Battery Usage

then selected Unrestricted, things started working as expected. So Maybe check out the background restrictions and try to get your user to allow your app to run in the background.

Hope that helps.

Please can u show me ur fcm JSON payload?

DarkcoderSe commented 7 months ago

@serveroid I was having this problem when the app was killed. Only on Android. I couldn't get a push, and then when I opened the app all of my pushes would appear at the same time.

If I opened the phone settings and went to --

Settings --> Apps --> 'My App' --> App Battery Usage

then selected Unrestricted, things started working as expected. So Maybe check out the background restrictions and try to get your user to allow your app to run in the background.

Hope that helps.

I don't think that's an good idea to display prompt for disabling the battery optimization for our app to each user. then how come whatsapp, snapchat etc sending notifications with battery atomization ON?

CandidlyRed commented 3 months ago

Agreed, I'm curious as to how apps like whatsapp and snapchat are able to send notifications in a killed state with battery optimization on