繁体   English   中英

从 js 中的 firebase 远程配置读取默认值给出错误资源未找到

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

当我的应用程序未连接到互联网时,希望从从 firebase 控制台下载的文件中读取默认值,而不是代码中指定的默认值。

浏览了以下文档 - https://firebase.google.com/docs/remote-config/get-started?platform=web#firebase-console_1

此外,这就是图书馆所说的 -

也根据它说的文件

/** * 从资源文件中设置默认值。 * 在 iOS 上,这是一个 plist 文件,在 Android 上,这是一个 XML defaultsMap 文件。 * * 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 不带扩展名的 plist/xml 文件名。 */ setDefaultsFromResource(resourceName: string): Promise;

上面尝试过,没有任何效果下载文件并将其保存在应用程序中的某个位置。 但是当我试图读取这些值时,它会出错。 以下是代码

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

这给出了错误 - 说 remote_config_defaults.json 不存在。 我也尝试过

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

现在它不接受这个文件的值,而是接受默认值。

如何让它发挥作用? 我正在使用 react native

“我正在使用 react native”

然后,您需要以适用于 react-native 的方式包含 JSON 文件,并以适用于 react-native 的方式读取它,然后从文件中设置您的默认远程配置参数。

从本质上讲,这不是一个“远程配置”问题 - 这是一个“我如何在 react-native 中保存/加载/使用 JSON 文件”问题。 如果它说“文件不存在”,这意味着你没有正确加载它

我认为已经存在更好的问题,例如: How to fetch data from local JSON file on react native?

暂无
暂无

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

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