Commit 3049056d authored by Ethan Milano's avatar Ethan Milano Committed by Libin Lu

Adding .remove() method to FCM.on() (#263)

* fixed documentation

* added .unsubscribe() method

* fix

* fix

* remove instead of unsubscribe
parent f16286cb
......@@ -268,7 +268,7 @@ class App extends Component {
console.log(token)
// store fcm token in your server
});
this.notificationUnsubscribe = FCM.on('notification', (notif) => {
this.notificationListener = FCM.on('notification', (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
......@@ -277,16 +277,16 @@ class App extends Component {
//app is open/resumed because user clicked banner
}
});
this.refreshUnsubscribe = FCM.on('refreshToken', (token) => {
this.refreshTokenListener = FCM.on('refreshToken', (token) => {
console.log(token)
// fcm token may not be available on first load, catch it here
});
}
componentWillUnmount() {
// prevent leaking
this.refreshUnsubscribe();
this.notificationUnsubscribe();
// stop listening for events
this.notificationListener.remove();
this.refreshTokenListener.remove();
}
otherMethods(){
......
......@@ -73,12 +73,9 @@ FCM.on = (event, callback) => {
const nativeEvent = eventsMap[event];
if (!nativeEvent) {
throw new Error('FCM event must be "refreshToken" or "notification"');
}
const listener = DeviceEventEmitter.addListener(nativeEvent, callback);
return function remove() {
listener.remove();
};
return DeviceEventEmitter.addListener(nativeEvent, callback);
};
FCM.subscribeToTopic = (topic) => {
......
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