@@ -284,6 +284,40 @@ NOTE: `com.evollu.react.fcm.FIRLocalMessagingPublisher` is required for presenti
...
@@ -284,6 +284,40 @@ NOTE: `com.evollu.react.fcm.FIRLocalMessagingPublisher` is required for presenti
import {Platform} from 'react-native';
import {Platform} from 'react-native';
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm';
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm';
// this shall be called regardless of app state: running, background or not running. Won't be called when app is killed by user in iOS
FCM.on(FCMEvent.Notification, async (notif) => {
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
if(notif.local_notification){
//this is a local notification
}
if(notif.opened_from_tray){
//app is open/resumed because user clicked banner
}
await someAsyncCall();
if(Platform.OS ==='ios'){
//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom
// fcm token may not be available on first load, catch it here
});
class App extends Component {
class App extends Component {
componentDidMount() {
componentDidMount() {
FCM.requestPermissions(); // for iOS
FCM.requestPermissions(); // for iOS
...
@@ -292,45 +326,14 @@ class App extends Component {
...
@@ -292,45 +326,14 @@ class App extends Component {
// store fcm token in your server
// store fcm token in your server
});
});
// NOTE: if you want to handle notifications when app is closed, put another handler outside of component lifecycle because components won't be initialized.
// there are two parts of notif. notif.notification contains the notification payload, notif.data contains data payload
// do some component related stuff
if(notif.local_notification){
//this is a local notification
}
if(notif.opened_from_tray){
//app is open/resumed because user clicked banner
}
await someAsyncCall();
if(Platform.OS ==='ios'){
//optional
//iOS requires developers to call completionHandler to end notification process. If you do not call it your background remote notifications could be throttled, to read more about it see the above documentation link.
//This library handles it for you automatically with default behavior (for remote notification, finish with NoData; for WillPresent, finish depend on "show_in_foreground"). However if you want to return different result, follow the following code to override
//notif._notificationType is available for iOS platfrom