zo0r / react-native-push-notification

React Native Local and Remote Notifications
MIT License
6.73k stars 2.05k forks source link

iOS - Local Scheduled Notification not triggering onNotification in background #1879

Closed JakeMotta closed 3 years ago

JakeMotta commented 3 years ago

Browsed many of the other issues, but didn't quite see a clear answer / directly relevant case, so I figured I'd ask.

react-native: 0.61.5 react-native-push-notification: 7.2.1

My app has react-native-push-notifications configured and working (mostly) as intended, with my local notifications triggering in the foreground as expected. I have a server that is using node-pushnotifications, and those are working as intended as well.

The remote notifications (from my server) are properly triggering my app (onNotification) in the background, and I'm able to execute some logic as a result. However, this is not the case when using localNotificationSchedule, which is only triggering onNotification when the app is in the foreground, when I need it to also trigger in the background.

Just to be clear, I am getting local notifications in the background, they just aren't triggering the onNotification function. It is possible to use localNotifications to trigger onNotification in the background, right?

I feel like I've read into this a bit too much the past few days, and have over-confused myself. Any advice would be appreciated.

Some code snippets I've tried (using NotifService & Push Notification library). Both triggering onNotification in foreground, but not in background.

image image

Dallas62 commented 3 years ago

Hi @JakeMotta

However, this is not the case when using localNotificationSchedule, which is only triggering onNotification when the app is in the foreground, when I need it to also trigger in the background.

This is not possible with the library, and it's not the aim of a local notification to trigger "background-task".

Please take a look to: https://github.com/transistorsoft/react-native-background-fetch https://github.com/jamesisaac/react-native-background-task

Regards,

Dallas62 commented 3 years ago

Same as #1877

JakeMotta commented 3 years ago

Hi @JakeMotta

However, this is not the case when using localNotificationSchedule, which is only triggering onNotification when the app is in the foreground, when I need it to also trigger in the background.

This is not possible with the library, and it's not the aim of a local notification to trigger "background-task".

Please take a look to: https://github.com/transistorsoft/react-native-background-fetch https://github.com/jamesisaac/react-native-background-task

Regards,

Glad to know. I was starting to lose my mind thinking everyone was getting this to work except me... Thanks for the prompt reply!