localStorage no longer working in iOS 7 WebView

2019-05-24 10:19发布

问题:

I am developing an HTML5 web app that is run from a WebView inside an iOS app. Once the users upgrade to iOS7, localStorage stops working and the app (which uses jQuery/jQuery Mobile) just shows the spinner.

I've run some tests using Modernizr and it does not detect support for localStorage in the WebView within the app. This is strange, because it works fine in Safari on the iPad with iOS7.

Has anyone else run into this issue or have a magical fix? The only client-side web storage API that seems to work is Web SQL in iOS7 WebView, and if I can help it I'd rather not have to use that.

回答1:

Try out this cookie policy setting from the gist: https://gist.github.com/steveriggins/6652508

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];


回答2:

Since upgrading to iOS7 everything stored in localStorage seems to be wiped when the web page reloads.

<script>
function supports_html5_storage() {
  try {
return 'localStorage' in window && window['localStorage'] !== null;
  } catch (e) {
    return false;
  }
}
if(supports_html5_storage()){
 rString=localStorage.getItem("SerialID");
 alert("We have localStorage support "+rString);
 if(rString) if(rString.length>0) alert("SerialID is present");
} else {
 alert("We do not have localStorage support");
}
</script>


回答3:

Sorry for posting this as an answer, can't comment yet (Don't have 50 points).

Anyway, russau's answer, how do I integrate this with my HTML5 code? I am not programming in objective-C