簡體   English   中英

Firebase 遠程配置未更新和使用舊值+ Flutter

[英]Firebase remote config not updating and using older value+ Flutter

當我們在 Play 商店提供更高版本時。 此功能將用戶重定向到應用商店以安裝更新。 但它不適用於少數設備。 用戶仍在使用舊版本。 如果用戶清除存儲,則會顯示警報。 我們不能要求我們的用戶清除存儲空間。 任何幫助將不勝感激。

@override
  void initState() {
    super.initState();
    try {
      versionCheck(context);
    } catch (e) {
      print(e);
    }
   }


versionCheck(context) async {
        //Get Current installed version of app
        final PackageInfo info = await PackageInfo.fromPlatform();
        double currentVersion =
            double.parse(info.version.trim().replaceAll(".", ""));
    
        //Get Latest version info from firebase config
        final FirebaseRemoteConfig remoteConfig =
            await FirebaseRemoteConfig.instance;
    
        try {
          // Using default duration to force fetching from remote server.
          await remoteConfig.fetch();
          await remoteConfig.fetchAndActivate();
          remoteConfig.getString('force_update_current_version');
          double newVersion = double.parse(remoteConfig
              .getString('force_update_current_version')
              .trim()
              .replaceAll(".", ""));
          if (newVersion > currentVersion) {
            _showVersionDialog(context);
          }
        } on Exception catch (exception) {
          // Fetch throttled.
          print(exception);
        } catch (exception) {
          print('Unable to fetch remote config. Cached or default values will be '
              'used');
        }
      }

當我嘗試打印這些值時,我得到相同的值 new:160.0 current:160.0,從設置中清除應用程序的存儲會顯示警報。

我認為您的代碼總體上對我來說是正確的。 雖然有一條多余的線:

remoteConfig.getString('force_update_current_version');

但這應該沒問題。

我擔心的是你替換了你所有的. 為空並將版本轉換為數字。 如果有兩個版本,如1.21.41.2.15 ,這可能會導致錯誤。 第一個應該是更新的,但是代碼會得到1214 > 1215 is false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM