Cordova 3.6.x的本地存储持久性如何



我很想知道localStorage在Cordova 3.6.x上的持久性如何?

存储应用程序的配置是否足够好?

如果我从AppStore/GooglePlay更新应用程序,它仍然保存着用户收集的数据,会发生什么?

如果不是,如果我想要一个带有cordova应用程序的持久和预填充数据,你会建议我使用什么cordova插件?

提前谢谢。

我看到了许多关于本地存储的链接,但遗憾的是,还没有找到确切的答案。我可以建议你一个数据库,SQLite包装插件

这很简单,效果很好。希望它能满足您的所有需求,包括预填充的数据库。

几个例子:

//Pre-populated database
//For Android & iOS (only): put the database file in the www directory and open the database like:
var db = window.sqlitePlugin.openDatabase({name: "my.db", createFromLocation: 1});

使用

// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
  var db = window.sqlitePlugin.openDatabase({name: "my.db"});
  db.transaction(function(tx) {
    tx.executeSql('DROP TABLE IF EXISTS test_table');
    tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
    // demonstrate PRAGMA:
    db.executeSql("pragma table_info (test_table);", [], function(res) {
      console.log("PRAGMA res: " + JSON.stringify(res));
    });
    tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
      console.log("insertId: " + res.insertId + " -- probably 1");
      console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
      db.transaction(function(tx) {
        tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
          console.log("res.rows.length: " + res.rows.length + " -- should be 1");
          console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
        });
      });
    }, function(e) {
      console.log("ERROR: " + e.message);
    });
  });
}

您可以从文档中了解所有内容。

如果你不违反任何限制,我看不会有问题。看看关于限制的帖子:子域的HTML5本地存储大小限制

还有iOS 7网络视图和本地存储持久性

你可以去https://github.com/jcfant/cacheJS或者如果您使用Ionic或Angular:

  • http://learn.ionicframework.com/formulas/localstorage/
  • https://github.com/grevory/angular-local-storage

您可以使用cordova插件nativestorage

用法:NativeStorage.setItem("key", "value", success, error);

最新更新