Useful or not, from you.
react-native-firebase firebase.config().fetch() returns error "Error: fetch() operation cannot be completed successfully."

Issue

Followed the below example using Remote Config. But I am getting error.

if (__DEV__) {
  firebase.config().enableDeveloperMode();
}

// Set default values
firebase.config().setDefaults({
  hasExperimentalFeature: false,
});

firebase.config().fetch()
  .then(() => {
    return firebase.config().activateFetched();
  })
  .then((activated) => {
    if (!activated) console.log('Fetched data not activated');
    return firebase.config().getValue('hasExperimentalFeature');
  })
  .then((snapshot) => {
    const hasExperimentalFeature = snapshot.val();

    if(hasExperimentalFeature) {
      // call some function
    }

    // continue booting app
  })
  .catch(console.error);

It returns an error : Error: fetch() operation cannot be completed successfully

screen shot 2018-08-07 at 3 25 50 pm

Environment

  1. Application Target Platform: Android
  2. Development Operating System: MacOS High Sierra
  3. Build Tools: Xcode buildToolsVersion = "27.0.3" minSdkVersion = 16 compileSdkVersion = 27 targetSdkVersion = 27 supportLibVersion = "27.1.0"
  4. React Native version: 0.56.0
  5. React Native Firebase Version: react-native-firebase@4.3.8
  6. Firebase Module: Remote Config
  7. Are you using typescript? no
That's a useful answer
Without any help

My solution was to put the fetch function inside a Promise. Ex:

try {
  return new Promise(
    (resolve) => {
      resolve(
      firebase.config()
      fetch()
        .then(() => {
          return firebase.config().activateFetched();
        })
        .then((activated) => {
          if (!activated) console.log('Fetched data not activated');
          return firebase.config().getValue('hasExperimentalFeature');
        })
        .then((snapshot) => {
          const hasExperimentalFeature = snapshot.val();

          if (hasExperimentalFeature) {
            // call some function
          }

          // continue booting app
        })
        .catch(console.error)
    )
  );
} catch (err) {
  console.warn(err)
}