问题
From my extensive reading, the iOS 5.1 localStorage/WebSQL behavior change that Apple instituted has been fully rolled into Cordova 1.6.0. However, while running on my (new) application on Cordova 1.7.0 and iOS 5.1.1, I am still seeing ugly, incorrect behavior.
I use window.localStorage to store and retrieve data. E.g. window.localStorage.getItem("activeFormId") window.localStorage.setItem("activeFormId", formId); These work flawlessly during the same session of the Cordova-based app. If I background the app with the main iOS button then resume, that usually works as well.
However, the moment I kill the application (double-tap, long-press, tap the red circle) and relaunch, all localStorage data is lost. I have verified this with jsconsole.com as well.
Are there additional steps I need to take to ensure the persistence bug fixes are working? Any help is greatly appreciated.
回答1:
Try using 1.7 - I had a similar issue and once I upgraded to 1.7 everything worked like it used to.
Try using localStorage vs window.localStorage syntax.
Also set what ever you're trying to call as a global variable...
var globalVar;
function onDeviceReady(){
globalVar = localStorage.getItem('something');
}
来源:https://stackoverflow.com/questions/10881059/localstorage-cleared-on-app-restart-with-cordova-1-7-and-ios-5-1-1