1

I'm interested to know how persistent localStorage is on Cordova 3.6.x?

Is it good enough to store configuration of application?

What happens if I update application from AppStore/GooglePlay is it still hold the collected data of user?

If not what cordova plugin will you suggest me to use if I want a persistent and pre-populated data with cordova application?

Thanks in advance.

hackp0int
  • 4,052
  • 8
  • 59
  • 95
  • I see no reason this question should've gotten a -1. Can anyone explain why this is a bad question? – Abe Fehr Aug 03 '15 at 17:14
  • @AbeFehr I don't also. ppl think that hard questions is not ok to ask because it doesn't give'm easy points – hackp0int Aug 04 '15 at 06:27

3 Answers3

0

If you do not run against any limits I dont see that there will be a problem. Take a look at that post about limits: HTML5 localStorage size limit for subdomains

Also iOS 7 webview and localStorage persistence

You could go for https://github.com/jcfant/cacheJS or if you use Ionic or Angular:

Community
  • 1
  • 1
  • 2
    lots of links. can you please tell me in short 'if someone update the app will local storage persist?' – AtanuCSE Mar 25 '15 at 08:41
  • This actually very interesting question. I think it's my main concern. – hackp0int Mar 25 '15 at 08:45
  • Yes is does survive an update - I can tell form my own experience. If you are not sure, [this guy](http://stackoverflow.com/a/9027599/1274157) says the same ;) – Mathias Maciossek Mar 25 '15 at 12:36
  • @MathiasMaciossek This is not the question he says exactly what I know. This is actually a proof for my question. – hackp0int Mar 26 '15 at 07:59
  • localStorage, Web SQL ,IndexDB are all persistent across updates for iOS and Android. They are however wiped when you delete the app completely. – Mathias Maciossek Mar 26 '15 at 11:57
  • That's not true for iOS. Since iOS 5 the localStorage file is saved in the Library/Caches directory and this directory may be deleted by the OS if the system is low on space. – Kiki May 04 '16 at 11:16
0

I've seen many links regarding local storage, unfortunately definite answer isn't found yet. I can suggest you a database, SQLite wrapper plugin

This is simple and works just fine. Hopefully it'll fulfill all your requirements including pre-populated database.

Few examples:

//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});

Usage

// 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);
    });
  });
}

You can know everything from the documentation.

AtanuCSE
  • 8,832
  • 14
  • 74
  • 112
-1

You can use cordova-plugin-nativestorage

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