Push notifications using Firebase
Firebase incorporates a push notification service for iOS and Android, but it unfortunately doesn't provide any JavaScript on their SDK to use it. For this matter, an open source library was created bridging the Objective-C and Java SDKs into a React Native module: react-native-fcm
.
We won't cover the installation of this module in this book, as it's a changing process that can be better followed on its repository at https://github.com/evollu/react-native-fcm.
We decided to abstract the logic for this module on our src/notifications.js
file to make it available for every component while keeping its maintainability. Let's take a look at this file:
/*** src/notifications.js ***/ import {Platform} from 'react-native'; import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm'; let notificationListener = null; let refreshTokenListener = null; const API_URL = 'https://fcm.googleapis.com/fcm/send';...