简体   繁体   中英

Read default values from firebase remote config in js gives error resource not found

when my app is not connected to internet would like the default values to be read from the file downloaded from the firebase console and not the default values specified within the code.

Went through the following documentation - https://firebase.google.com/docs/remote-config/get-started?platform=web#firebase-console_1

Also, this is what the library says -

Also as per the documentation it says

/** * Sets the default values from a resource file. * On iOS this is a plist file and on Android this is an XML defaultsMap file. * * js * // put in either your iOS or Android directory without the file extension included (.plist or.xml) * await firebase.remoteConfig().setDefaultsFromResource('config_resource'); * * // resource values will now be loaded in with your other config values * const config = firebase.remoteConfig().getAll(); * js * // put in either your iOS or Android directory without the file extension included (.plist or.xml) * await firebase.remoteConfig().setDefaultsFromResource('config_resource'); * * // resource values will now be loaded in with your other config values * const config = firebase.remoteConfig().getAll(); * js * // put in either your iOS or Android directory without the file extension included (.plist or.xml) * await firebase.remoteConfig().setDefaultsFromResource('config_resource'); * * // resource values will now be loaded in with your other config values * const config = firebase.remoteConfig().getAll(); * * * @param resourceName The plist/xml file name with no extension. */ setDefaultsFromResource(resourceName: string): Promise;

Tried above and nothing works Downloaded the file and kept it somewhere in app. But when i am trying to read the values, it gives error. Following is the code

 //this runs there is no network.
   if (!!source) {

   remoteConfig().setDefaultsFromResource('remote_config_defaults.json');
    
  } else {
     await remoteConfig().fetchAndActivate();
  }
  const config = remoteConfig();



setAppConfig('RemoteKey', 'Code_Default_Value', (key) => config.getString(key));
  

This is giving the error - saying remote_config_defaults.json does not exist. I tried following as well

const rcDefaults = require('./src/utils/remote_config_defaults.json');
remoteConfig().setDefaultsFromResource =rcDefaults; 

now it does not takes in the values of this file but from the default values.

How to make it work? I am working with react native

"I am working with react native"

Then you need to include the JSON file in a way that works with react-native, and read it in a way that works with react-native, then set your default remote-config parameters from the file.

At heart, this is not a "remote config" question then - it is a "how do I save / load / use a JSON file in react-native" question. And if it says "the file does not exist" that means you are not loading it correctly

I think there are better questions already in existence for that, for example: How to fetch data from local JSON file on react native?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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