LocalStorage does not go to standalone web app
I just need to hold some simple data in a standalone iOS web app (using apple-mobile-web-app-capable
etc.). The data is determined when the user visits the site and is saved to localStorage.name
, etc. This same page is "saved to the main screen", but when I get there, the output localStorage.name
, etc. Returns undefined
.
I go back to Safari and it still knows the information. I pulled it out using my laptop developer console and I can still get all the data. It's not even a different page, let alone a different domain or whatever. Everything I've read tells me that I localStorage
should (with minor caveats to change this data) share between Safari and the standalone app. What am I missing?
Here's the gist of the code:
if (!window.navigator.standalone) {
// show Safari content
if (localStorage.name != void 0 && localStorage.var2 != void 0) {
// show normal, "add this to your home screen" language -
// this screen shows properly
} else {
// show "We weren't passed our variables" language
}
} else {
// Show standalone/offline content
if (localStorage.name != void 0 && localStorage.var2 != void 0) {
// Show normal standalone app content using localStorage variables.
// I'm not seeing this.
} else {
// Show "error" text, which is what I'm getting
document.body.removeChild(document.getElementById('container'));
var helper = document.createElement('section')
helper.id="helper"
helper.innerHTML = '<h1>Sorry</h1>'
+ '<p>There seems to be a problem with the app.</p>'
+ '<pre>'
+ " Name: " + localStorage.name + "\n"
+ " var2: " + localStorage.var21 + "\n"
+ '</pre>';
document.body.insertBefore(helper,document.body.firstChild)
}
}
For what it's worth, I'm on iOS 6.1. So it shouldn't be an "old" problem. What am I doing wrong?
source to share
This comment: iOS 'Web App' has different local storage than Mobile Safari
... has an answer. Local storage is now completely separate from Safari to the native app.
source to share