0
votes

I am configuring and initialising firebase app still FCM messaging results in an error saying Firebase App not initialised.

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,

2

2 Answers

0
votes

You have to call FCM.getFCMToken() inside FCM.requestPermissions().then() because requestPermissions is async

0
votes

According to "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.

As compare to reac-native-fcm you have to use react-native-firebase. Here you can find the docs and its easy to use and integrate in react-native.