zo0r / react-native-push-notification

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

iOS silent remote push notification when app is killed #345

Closed chiformihai closed 4 years ago

chiformihai commented 7 years ago

Everything works ok when the app is in background or has been killed by the OS, but is there any chance of showing a notification when the app is killed by the user? The phone does vibrate, so the silent remote push notification is received, but there's not visual notification

React native version: 0.37.0

npomfret commented 7 years ago

Not on iOS, but yes on Android. Please check the trouble shooting guide.

chiformihai commented 7 years ago

On Android everything works well. I've read the troubleshooting, but it doesn't specify this particular case (or maybe I don't understand, sorry if so), though I've seen this in some other issues. Is this the issue: (iOS) The OS can penalise your app for not calling the completion handler and will stop (or delay) sending notifications to your app. This will be supported from RN-0.38 ? If so, an upgrade to RN 0.38 will solve it? I would use the noisy remote push notifications, but the problem is userInteraction is always true on iOS and that is why I went for mixed (plus the flexibility that it gives you). So is there any solution to show the notification when the app is killed by the user? Would a possible solution be to send alert: {title: 'someTitle', body: 'someBody'} in notification's payload on the server, and in client's didReceiveRemoteNotification manipulate somehow the notification, so that if app's state is anything but inactive then remove that alert property, so it will act as a silent push notification ?

npomfret commented 7 years ago

I think there's a problem with the user interaction flag, I've heard other complaining. Though I'm not sure what it's supposed to represent.

In iOS, if the user kills the app then no silent (content-available=1) notifications will be delivered, no matter what. But noisy ones will be delivered (I think!)

npomfret commented 7 years ago

... my advice, and what has worked well for me is to only send silent notifications, and if you want noisy ones then use a local notification in your app. If the server can detect that a silent notification hasn't been delivered (after a while) you can assume the app has been killed and send them a noisy one. I think this is the approach that What'sApp takes.

chiformihai commented 7 years ago

But the problem is on the server the success callback is called after sending the notification, because it is sent to the device. The phone vibrates, just that the notifications does not appear.

For the server I use node-pushnotifications, which uses node-apn for iOS notifications

noambonnie commented 6 years ago

@npomfret - Is there anything special that needs to happen for onNotification to be called when the app is not started? I'm trying to create a local notification based on data I get from a silent notification. But on iOS when the app is not running (e.g. after device restart) nothing is being invoked.

github-actions[bot] commented 4 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.