Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 可能未处理的承诺拒绝id:FCM事件订阅无效_Javascript_Android_React Native_Push Notification_React Native Fcm - Fatal编程技术网

Javascript 可能未处理的承诺拒绝id:FCM事件订阅无效

Javascript 可能未处理的承诺拒绝id:FCM事件订阅无效,javascript,android,react-native,push-notification,react-native-fcm,Javascript,Android,React Native,Push Notification,React Native Fcm,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 =&

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);
});