index.js
import FCM from "react-native-fcm";
class Register extends Component {
constructor(props) {
super(props);
componentDidMount () {
// this method generate fcm token.
FCM.requestPermissions();
FCM.getFCMToken().then(token => {
console.log("TOKEN (getFCMToken)", token);
});
// This method get all notification from server side.
FCM.getInitialNotification().then(notif => {
console.log("INITIAL NOTIFICATION", notif)
});
// This method give received notifications to mobile to display.
this.notificationUnsubscribe = FCM.on("notification", notif => {
console.log("a", notif);
if (notif && notif.local_notification) {
return;
}
this.sendRemote(notif);
});
// this method call when FCM token is update(FCM token update any time so will get updated token from this method)
FCM.on("refreshToken", token => {
console.log("TOKEN (refreshUnsubscribe)", token);
this.props.onChangeToken(token);
});
}
sendRemote(notif) {
console.log('send');
FCM.presentLocalNotification({
title: notif.title,
message: notif.message,
priority: "high",
click_action: notif.click_action,
show_in_foreground: true,
local: true
});
}
componentWillUnmount() {
this.refreshUnsubscribe();
this.notificationUnsubscribe();
}
Это часть моего кода для генерации токена и обработки уведомлений с сервера. Что я плохо делаю? Не могу понять. Пожалуйста, помогите. Заранее спасибо. Ниже приведен снимок экрана с предупреждающей ошибкой.
Я понимаю, что это слишком поздно, но столкнувшись с той же проблемой, я исправил ее, импортируя
import FCM, {FCMEvent} from "react-native-fcm";
а затем с помощью FCMEvent для подписки на события:
this.notificationSubscribe = FCM.on(FCMEvent.Notification, notif => {
this.showNotification(notif);
});