- This topic has 8 replies, 5 voices, and was last updated 10 years, 11 months ago by living.horses.
-
AuthorPosts
-
living.horsesMemberi thought i solved the issue of saving user input, and then having that information automatically populate the fields when app is reopened.
however, if i turn device off and turn back on, the data is lost. ( i am using the sample localstorage layout for testing at this stage)my code is
function update() {
//alert(‘update’);
if (!window.localStorage) {
warnNoLocStorage();
return;
}var key = $(‘#m1-storetest1-keyfield’).val();
var data = localStorage.getItem(key);$(‘#m1-storetest1-datafield’).val(data);
}function save() {
//alert(‘save’);
if (!window.localStorage) {
warnNoLocStorage();
return;
}var key = $(‘#m1-storetest1-keyfield’).val();
var data = $(‘#m1-storetest1-datafield’).val();localStorage.setItem(key,data);
alert(‘Save completed’);
}function storageValue() {
var uno = document.getElementById(“keyfield”);
var key = uno.value;
localStorage[“key”] = key;
var dos = document.getElementById(“datafield”);
var data = dos.value;
localStorage[“data”] = data;
alert(“Your stored values are: ” + key + “,” + data + “);
localStorage.setItem(key, data);
checkLocalStorage();
}function checkLocalStorage() {
var div = document.getElementById(“storetest1”);
div.innerHTML = “The current values are: ” + localStorage[“key”] + “, ” + localStorage[“data”];
}
checkLocalStorage();
}thank you in advance
Code_AMemberI did not know that local storage was wiped when the device was restarted. I am using it in my app right now too and if that is the case then I will also need to come up with another solution.
There are 2 options that come to mind:
1. Store the data in a file and read/write using PhoneGap File API.
2. Store the data in an web server database (if you have access to one) and use AJAX to read/write.
I have never messed with option 1 but found a few examples here by doing a quick search. I have used option 2 in my app so I know that is a solution if necessary but requires an internet connection for communication to the server, so probably not ideal for storing “local” data.
BrandonMemberI have not noticed localstorage being cleared on restart, but I will do a test to verify this.
Edit: I can confirm on iphone 4s, iOS 7.0.3 that the local storage data is saved after restarting.
rick.gommersMember@Code A wrote:
I did not know that local storage was wiped when the device was restarted. I am using it in my app right now too and if that is the case then I will also need to come up with another solution.
There are 2 options that come to mind:
1. Store the data in a file and read/write using PhoneGap File API.
2. Store the data in an web server database (if you have access to one) and use AJAX to read/write.
I have never messed with option 1 but found a few examples here by doing a quick search. I have used option 2 in my app so I know that is a solution if necessary but requires an internet connection for communication to the server, so probably not ideal for storing “local” data.
I’ve done a test once with option 1. It’s not very difficult. Just be sure to add permissions during build process.
Check it out:
document.addEventListener("deviceready", onDeviceReady, false); // Cordova is ready // Load fileSystem function onDeviceReady() { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFileSystemFail); } //Load or Create directory function gotFS(fileSystem) { var directoryEntry = fileSystem.root; alert(directoryEntry.fullPath); //Where TestTestTest is directory name in this case directoryEntry.getDirectory("TestTestTest", {create: true, exclusive: false}, gotDir, onDirectoryFail) } //Load or Create readme.txt function gotDir(directoryEntry) { alert('dir success!'); alert(directoryEntry); directoryEntry.getFile("readme.txt", {create: true, exclusive: false}, gotFile, fail); } //Create FileWriter function gotFile(fileEntry) { alert('got file!'); fileEntry.createWriter(gotFileWriter, fail); } //Write contents to the file function gotFileWriter(writer) { writer.write("Line 1\n\nLine 2"); } function fail(error) { alert(error.code); } function onDirectoryFail(error) { alert("Unable to create new directory: " + error.code); } function onFileSystemFail(evt) { alert(evt.target.error.code); }
living.horsesMemberI am testing it out on my xperia acros.
I didn’t even consider any permissions – completely slipped my mind I was too busy trying to work out the function. lol
thank you for the above advice, will attempt that tonight and let you all know how I went.
much appreciated 😉
living.horsesMemberI thought I had done pretty well, when i could exit the app, and return to find the data still there, and then had a wild thought ‘what if i turn it off?’
Just as well for me I did try it.
HOWEVER, I did allow for any permissions during the build process, so hopefully that was it.I also need it to save to the phone itself, as the app has to be able to work without an internet connection.
off topic, can a certificate.cer (for google) be ‘re-made’? i don’t know how or where, but apparently the certificate & key that was stored/saved in my build file is not the same now as when i last published my app. Which means my free app of 5000+ installs, i can no longer update! but my paid app certificate is still the same?? it has thrown me for a loop, as i don’t remember generating a new one and replacing it.
support-octavioMemberHi living.horses,
It is cool to see your app’s success. Please note that certificates are unique and you can not generate a duplicate. The documentation we provide stresses that you have to be extra careful to keep these files safe and secure. If it is lost then you must start over. The app center only keeps this info around for short terms during the frequent build processs as a convenience. I have asked the dev team to review and learn if there is additional info or assistance we can provide.
living.horsesMemberThan you Octavio, I’m quite thrilled to be honest, having my first attempt basic app, up against big name publishers like Horse & country, and Horsezone. admittedly the content is very different, but ease of use plays a large role.
I thought I was being so careful with the certificates, I even have multiple copies of the file on different storages, and they all have the same certificate that Google Play tells me is wrong. But i guess what’s done is done. At least I can always modify the information in my listing to point to a new version, it’s just a shame that I will lose all the ratings, and the 5000+ downloads reference.
I much appreciate you asking the dev team, and maybe, just maybe, there might be some good news.
In the meantime, I will work on saving the data code, and then launch it in iTunes 🙂
living.horsesMemberJust out of curiosity, I went and checked all the dates for the certificate.cer and apk google upload. Here is what i find.
I last uploaded my app to Google on November 18, 2013.
My computer tells me the .cer file was modified on August 17, 2013, but created November 18, 2013. Now I am confused.
-
AuthorPosts