从Playstore更新应用程序时如何清除本地存储?

3 android angularjs ionic-framework

我已经使用Angular和Ionic开发了一个Android移动应用程序。我已经将其上传到以1.0版本运行的Playstore中。现在,我要在Playstore中更新我的应用。

用户更新应用程序时,应清除本地存储。谁能帮助我前进?

我想在每次安装时清除我的应用程序的本地存储。

kol*_*odi 5

  1. 将版本代码变量添加到您的应用。
  2. 每次您的应用启动时,请检查本地存储是否保存了相同版本的代码。如果匹配,则不执行任何操作,否则执行清理并将新代码保存到localstorage。

编辑:在您的应用程序开始的某个地方:

 /*your currnt app version, 
  you should manually update it here*/
  var version = "200";
  /*get version code stored in localstorage*/
  var savedAppVersion = localStorage.getItem("version");
  /*if there is one check if it is the same*/
  if (savedAppVersion && savedAppVersion === version) {
    // do nothing
  } else {
    /*clear all local storage*/
    localStorage.clear();
    /*save new code to ls*/
    localStorage.setItem("version", version);
  }
Run Code Online (Sandbox Code Playgroud)

编辑2:您可以使用cordova插件自动获取应用程序版本: ngCordova

因此,您可以使用$ cordovaAppVersio服务:

$cordovaAppVersion.getVersionNumber().then(function (version) {
        // use version here
      });
  }, false);
Run Code Online (Sandbox Code Playgroud)