【问题标题】:Perform in app force update using current and required build numbers使用当前和所需的内部版本号执行应用程序强制更新
【发布时间】:2021-06-23 11:17:18
【问题描述】:

我想强制更新我的应用。

这是我到目前为止所做的。

  1. 使用 package_info_plus 获得了我的应用程序的当前构建版本
  2. 获得了我存储在 firebase 远程配置中的强制构建版本。所以我使用了这个包:firebase_remote_config

然后我比较了两个版本号,看看是否需要更新。之后我该怎么办?

这是我的代码:

 void initState(){ 
     super.initState();
     checkForUpdate();
    _initPackageInfo();
    _enforcedVersion();

if(int.parse(_packageInfo.buildNumber) > int.parse(enforcedBuildNumber))
{ 
    //How to force update? 


}
}

Future<void> _initPackageInfo() async {
    final info = await PackageInfo.fromPlatform();
    setState(() {
      _packageInfo = info;
    });
  }
Future<void> _enforcedVersion() async {
  final RemoteConfig remoteConfig =  RemoteConfig.instance;
  await remoteConfig.setConfigSettings(RemoteConfigSettings(
              fetchTimeout: const Duration(seconds: 10),
              minimumFetchInterval: Duration.zero,
            ));
  await remoteConfig.fetchAndActivate();
   setState(() {
     enforcedBuildNumber = remoteConfig.getString('enforced_build_number');
    });
}

【问题讨论】:

    标签: flutter in-app-update app-update


    【解决方案1】:

    您可以显示一个不可关闭的对话框,要求用户使用重定向按钮更新应用程序到设备应用商店。

    通过使用诸如url_launcher 之类的包,您可以轻松做到这一点:

    代码示例

    import 'dart:io' show Platform;
    
    import 'package:url_launcher/url_launcher.dart';
    
    // You can show a dialog like this
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (_) => AlertDialog(
        title: Text('Please update your app'),
        actions: [
          TextButton(
            onPressed: launchAppStore,
            child: Text('Open App Store'),
          ),
        ],
      ),
    );
    
    // Method to open the appstore
    void launchAppStore() {
      /// Depending on where you are putting this method you might need
      /// to pass a reference from your _packageInfo.
      final appPackageName = _packageInfo.packageName;
    
      if (Platform.isAndroid) {
        launch("https://play.google.com/store/apps/details?id=$appPackageName");
      } else if (Platform.isIOS) {
        launch("market://details?id=$appPackageName");
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-19
      • 2020-09-07
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多