如何检查用户是否已从应用商店/播放商店更新了应用程序,然后清除异步存储?React native



我们在应用商店和播放商店中都有一个应用程序,但一旦用户更新了应用程序,它就无法正常工作,如果用户清除了缓存和存储,它就会正常工作。

我们想检查用户是否已经根据某个版本号从应用商店/播放商店更新了应用程序,然后清除异步存储

到目前为止,在react native中还无法知道这一点,但另一方面,您可以从这里使用native java for android进行检查。

boolean verifyInstallerId(Context context) {
// A list with valid installers package name
List<String> validInstallers = new ArrayList<>(Arrays.asList("com.android.vending", "com.google.android.feedback"));
// The package name of the app that has installed your app
final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());
// true if your app has been downloaded from Play Store 
return installer != null && validInstallers.contains(installer);
}

这里有一个CCD_ 1的本地解决方案,使用这个旧答案中的native。

我建议您在下一次更新中删除所有用户的存储以解决此问题。

如果你能指定你的错误,也许我们可以帮助它。

在这个新版本中,您可以执行类似的操作

const savedVersion = await AsyncStorage.getItem('savedVersion'); // this will return null, because the previous version didn't set this value
const currentVersion = DeviceInfo.getVersion();
if (!savedVersion||semver.lt(savedVersion, currentVersion)) {
await clearAllStorage();
await AsyncStorage.setItem('savedVersion', currentVersion);
}

相关内容

最新更新