My Local notification is working fine. But I just wanted to know how does it works with remote notification. Like below code is working fine with localNotification but how does it work with remote notification and what are the configuration we need to set on server
PushNotification.localNotification({
message: "My Notification Message"
});
+1
I agree, but I've been able to receive remote notifications in the app fine, it's just that they don't appear as card notifications to the OS. Local notifications do -- that's working fine. I'm on Android6 / RN 33 .
Is there some adjustment in the Android directory that needs to happen from RN32 -> 33. I'm beginning to think that I need to see what react-native upgrade does there because I never run that when I upgrade. Any thoughts on if that could be the issue? I guesss I could try a roll back.
I have the same behavior as ssomnoremac.
rn33, react-native-push-notification 2.1.1, android 4.2.2, 5.0.0
The content of the notification determines if or not is appears in the device's notification centre. Some notifications won't appear at all, they just invoke code in your app and it's up to the developer to choose if or not they want to add them to the notifications centre using a local notification
@npomfret does it mean that after >= 2.1.0... Whenever we receive a remote push notification,
For Android, we need to manually control whether to show the push notification in device notification centre. Whereas, for IOS we don't need to manually determine whether to show on notification centre or not.
No, there's no change in behaviour.
basically there are a number of types of notification for both iOS and android.
firstly, you have local notifications, which are the simplest. you run some code on the device and you can make a notification appear in the notification centre. there are differences between iOS and android in what can be displayed, but at a basic level they are pretty similar. you can choose the text, the sound, the vibration etc. they can be much more heavily customised in android but this plugin doesn't support a lot of it (yet).
then there are remote push notifications with come from a server. there are 2 types, both for android and for ios. I'll call them 'noisy' and 'silent'.
'Noisy' push notifications are handled by your device and do not interact with your application. they appear in the notification centre and can vibrate and make a sound. on android I believe these can be customised to the same extent as local notifications. The advantage of these is that they do not need your application to be running, they will alway just go into the notification centre.
'Silent' push notifications make their way into your app, and will trigger the 'onNotification' method in this module. For this reason they are very useful and are the most commonly used (i imagine). The content of the notification decides if or not it's 'noisy' or 'silent'. If you want a silent notification - on iOS you need to set a flag called content-available=1, and on android you need to add a 'payload' field. You can add a payload in iOS also, but that's not the trigger to make it a 'silent' notification.
If you want a notification that both makes its way into your app AND appears in the notification centre then the trick is to send a silent notification from your server, and when you handle it inside your app generate a local notification. This has the added advantage that you get the opportunity to send more detailed notification (because local notifications can be customised more that 'noisy' remote push notifications).
Now, if your app isn't running you may or may not get the silent notifications. It depends both on the OS and how your app was killed. On iOS for example, if the OS suspends your app and then kills it (which it will), your app will also start it up again (in the background) when a notification arrives. If the user killed the app, then a 'silent' notification will not be delivered, although 'noisy' ones will (because they don't need the app to be running). On android, if you have your manifest set up correctly you can actually have your app start even if the user killed it, and so all 'silent' notifications should be delivered to your app. However, you do need to structure your app in a certain way because when the OS start it in the background it won't start any of the react-native view stuff - so no react-native life-cycle methods will fire. In short, you need to make sure your push notification handling code is invoked by simply importing a file in index.android.js.
Thanks for your detailed explanation (this should be recorded in the README)
Sure. I'll start putting together a trouble shooting guide and stick it in there.
@npomfret Elaborating on a question I asked you on another thread...
I'm trying to do exactly what you describe - get a silent notification and generate a local notification. You say that iOS will restart the app if it was not killed by the user. Is there a way to test this? I couldn't make it happen. I tried opening many other apps hoping my app would be pushed out of memory, tried restarting the device. I never get the notification called.
Yes, if a user kills the app nothing can restart it except the user. If the OS kills the app (which it does quite liberally) then a silent push notification can resart it. I've not looked at this for ages (gave up with react native a long time ago), but I think the way to simulate it is to run the app on your device from xCode, and then use Xcode to stop the app. Send the silent push notification and you should see it start again.
Most helpful comment
No, there's no change in behaviour.
basically there are a number of types of notification for both iOS and android.
firstly, you have local notifications, which are the simplest. you run some code on the device and you can make a notification appear in the notification centre. there are differences between iOS and android in what can be displayed, but at a basic level they are pretty similar. you can choose the text, the sound, the vibration etc. they can be much more heavily customised in android but this plugin doesn't support a lot of it (yet).
then there are remote push notifications with come from a server. there are 2 types, both for android and for ios. I'll call them 'noisy' and 'silent'.
'Noisy' push notifications are handled by your device and do not interact with your application. they appear in the notification centre and can vibrate and make a sound. on android I believe these can be customised to the same extent as local notifications. The advantage of these is that they do not need your application to be running, they will alway just go into the notification centre.
'Silent' push notifications make their way into your app, and will trigger the 'onNotification' method in this module. For this reason they are very useful and are the most commonly used (i imagine). The content of the notification decides if or not it's 'noisy' or 'silent'. If you want a silent notification - on iOS you need to set a flag called
content-available=1, and on android you need to add a 'payload' field. You can add a payload in iOS also, but that's not the trigger to make it a 'silent' notification.If you want a notification that both makes its way into your app AND appears in the notification centre then the trick is to send a silent notification from your server, and when you handle it inside your app generate a local notification. This has the added advantage that you get the opportunity to send more detailed notification (because local notifications can be customised more that 'noisy' remote push notifications).
Now, if your app isn't running you may or may not get the silent notifications. It depends both on the OS and how your app was killed. On iOS for example, if the OS suspends your app and then kills it (which it will), your app will also start it up again (in the background) when a notification arrives. If the user killed the app, then a 'silent' notification will not be delivered, although 'noisy' ones will (because they don't need the app to be running). On android, if you have your manifest set up correctly you can actually have your app start even if the user killed it, and so all 'silent' notifications should be delivered to your app. However, you do need to structure your app in a certain way because when the OS start it in the background it won't start any of the react-native view stuff - so no react-native life-cycle methods will fire. In short, you need to make sure your push notification handling code is invoked by simply importing a file in
index.android.js.