I'm developing React-native app (iOS & Android).
Server connected through web-socket. Server sends notifications about some specific events. App suppose to notify user (using alerts). What if I need to notify user even if app is running in background or closed - how can i do that? Push notifications with this library will help in cases when app is in background, right? But it will not work if app is closed? So, how can i notify user if app is in background or closed?
Let's start with Android. The Android OS is designed to listen for push messages and upon receiving one, wake up the appropriate Android app to handle the push message, regardless of whether the app is closed or not.
You use a Service. Services can run in the background even when the app is closed, and can start when the device boots up so even if the user has restarted their phone but hasn't opened the app, you can still send push notifications via the Service class. Use AlarmManager to start your service at the given time.
We can use the React Native Firebase library to integrate FCM on Android and the push-notification-ios library to integrate APNs on iOS. Also, the React Native Firebase library offers a way to receive push notifications on iOS through FCM.
The library you referenced will indeed allow you to notify users even if the app is closed as it utilised Push Notifications. These are delivered to your users' devices no matter the state of your app.
When a user opens a push notification they are taken to your app. This Push Notifications tutorial is a good introduction to the system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With