加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – Flutter应用程序中的远程配置会在fetch上引发异常

发布时间:2020-12-14 14:49:55 所属栏目:百科 来源:网络整理
导读:我有一个Flutter应用程序,我使用远程配置来检索一些信息,但代码在获取数据时引发异常. 这是我设置远程配置的方法. FutureRemoteConfig setupRemoteConfig() async { final RemoteConfig remoteConfig = await RemoteConfig.instance; // Enable developer mo
我有一个Flutter应用程序,我使用远程配置来检索一些信息,但代码在获取数据时引发异常.

这是我设置远程配置的方法.

Future<RemoteConfig> setupRemoteConfig() async {
  final RemoteConfig remoteConfig = await RemoteConfig.instance;
  // Enable developer mode to relax fetch throttling
  remoteConfig.setConfigSettings(RemoteConfigSettings(debugMode: true));
  remoteConfig.setDefaults(<String,dynamic>{
    'categories': "food,drink",});
  await remoteConfig.fetch(expiration: const Duration(hours: 5));
  await remoteConfig.activateFetched();
  return remoteConfig;
}

此代码抛出以下异常:

Exception: Unable to fetch remote config

在我的控制台中它说:

W/FirebaseRemoteConfig(10456): IPC failure: 6503:NOT_AVAILABLE

我怎样才能解决这个问题?

解决方法

使用Try Catch包装你的fetch()和activateFetched()api调用

try {
    // Using default duration to force fetching from remote server.
    await remoteConfig.fetch(expiration: const Duration(seconds: 0));
    await remoteConfig.activateFetched();
  } on FetchThrottledException catch (exception) {
    // Fetch throttled.
    print(exception);
  } catch (exception) {
    print(
        'Unable to fetch remote config. Cached or default values will be '
        'used');
  }

请参见此处的官方示例:https://github.com/flutter/plugins/blob/master/packages/firebase_remote_config/example/lib/main.dart

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读