[英]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.4
和1.2.15
,这可能会导致错误。 第一个应该是更新的,但是代码会得到1214 > 1215 is false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.