简体   繁体   English

FCM-Firebase应用未初始化-React Native

[英]FCM - firebase App not initialised - React Native

I am configuring and initialising firebase app still FCM messaging results in an error saying Firebase App not initialised. 我正在配置和初始化Firebase应用程序,但FCM消息传递仍然导致错误,提示Firebase App未初始化。

import FCM from "react-native-fcm";

const firebaseConfig = {
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
messagingSenderId: "xxx",
storageBucket: "xxx",

};

const firebaseApp = firebase.initializeApp(firebaseConfig);

 class App extends Component {

 configureStore()
 {
  const store = createStore(reducer,undefined,compose(autoRehydrate()));
  persistStore(store,{ storage: AsyncStorage })
  return store;
 }

constructor(props)
{

   super(props);
}

componentDidMount()
{

   FCM.requestPermissions()
  .then(()=>console.log('granted'))
  .catch(()=>console.log('notification permission rejected'));

   FCM.getFCMToken()
    .then(token => {
       alert("TOKEN (getFCMToken)", token);
    })
   .catch((error)=>  alert(error))

 }
}

FCM notification permission is granted but then the getToken method results in an error of firebase app not initialised instead of initialising it at the top, 授予FCM通知权限,但getToken方法导致firebase应用未初始化而不是在顶部初始化的错误,

您必须在FCM.requestPermissions().then()调用FCM.getFCMToken() FCM.requestPermissions().then()因为requestPermissions是异步的

According to "react-native-fcm" , 根据“ react-native-fcm”

react-native-firebase now can do what react-native-fcm can so it is a waste of effort to build the same thing in parallel. 现在,react-native-firebase可以做react-native-fcm可以做的事情,因此,并行构建同一事物是浪费精力的。

As compare to reac-native-fcm you have to use react-native-firebase . 与reac-native-fcm相比,您必须使用react-native-firebase Here you can find the docs and its easy to use and integrate in react-native. 在这里,您可以找到文档及其易于使用和集成在react-native中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM