localStorage no longer working in iOS 7 WebView

╄→尐↘猪︶ㄣ 提交于 2019-12-08 02:53:51

问题


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>


来源:https://stackoverflow.com/questions/18964410/localstorage-no-longer-working-in-ios-7-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!