zo0r / react-native-push-notification

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

[IOS] onNotification not working (triggered) when app on foreground #922

Closed sandropoluan closed 3 years ago

sandropoluan commented 5 years ago

Everything is doing fine on Android and IOS. Except when on IOS and receiving and then clicking the notification when app on foreground, the onNotification callback is not working. But when I received and clicking the notification while the app is killed or not running, the app is starting up and then the onNotification callback work perfectly.

I use PushNotification.localNotificationSchedule.

Any idea what is going on?

jacquesdev commented 5 years ago

@sandropoluan - I'm experiencing the same problem, have you been able to resolve this by any chance?

arfa123 commented 5 years ago

I have also facing same problem. what is solution?

izzisolomon commented 5 years ago

Same problem here

izzisolomon commented 5 years ago

After spending 3 days on this, in my case turns out the APN notification generated by the backend was missing the property "content-available": 1 . once I added that to the "aps" object, onNotification started to fire! here is an example notification structure (from the apple docs):

{
"aps" : {
    "content-available" : 1
},
"acme1" : "bar",
"acme2" : 42

}

Cody1009 commented 5 years ago

same problem here. @izzisolomon I want to try your solution but where did you write that code? I use local notification from pure react-native module.

izzisolomon commented 5 years ago

@Cody1009 if you trigger the notifications locally you don't really need onNotification to fire, do you? I mean you can just call whatever you want at the same time you trigger the notification

HyeonjuPark commented 4 years ago

@izzisolomon What if I schedule local notification and want to check the user came from the notification or not?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.