Commit 421f1aa0 authored by Libin Lu's avatar Libin Lu Committed by GitHub

Update README.md

parent 8a3d1240
......@@ -284,16 +284,8 @@ NOTE: `com.evollu.react.fcm.FIRLocalMessagingPublisher` is required for presenti
import {Platform} from 'react-native';
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm';
class App extends Component {
componentDidMount() {
FCM.requestPermissions(); // for iOS
FCM.getFCMToken().then(token => {
console.log(token)
// 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.
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
// 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
......@@ -320,17 +312,28 @@ class App extends Component {
break;
}
}
});
this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
});
FCM.on(FCMEvent.RefreshToken, (token) => {
console.log(token)
// fcm token may not be available on first load, catch it here
});
class App extends Component {
componentDidMount() {
FCM.requestPermissions(); // for iOS
FCM.getFCMToken().then(token => {
console.log(token)
// store fcm token in your server
});
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
// do some component related stuff
});
}
componentWillUnmount() {
// stop listening for events
this.notificationListener.remove();
this.refreshTokenListener.remove();
}
otherMethods(){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment