【问题标题】:localStorage no longer working in iOS 7 WebViewlocalStorage 在 iOS 7 WebView 中不再工作
【发布时间】:2013-09-23 16:33:22
【问题描述】:

我正在开发一个 HTML5 网络应用程序,它从 iOS 应用程序内的 WebView 运行。用户升级到 iOS7 后,localStorage 停止工作,应用程序(使用 jQuery/jQuery Mobile)只显示微调器。

我使用 Modernizr 运行了一些测试,但它没有检测到应用内 WebView 中对 localStorage 的支持。这很奇怪,因为它在装有 iOS7 的 iPad 上的 Safari 中运行良好。

有没有其他人遇到过这个问题或有什么神奇的解决方法?唯一可行的客户端 Web 存储 API 是 iOS7 WebView 中的 Web SQL,如果我能提供帮助,我宁愿不必使用它。

【问题讨论】:

  • 您的 html 页面是如何托管的?
  • 我也面临这个问题,但仅限于禁用 Cookie 时。否则它正在工作。
  • html 在应用程序中本地运行。我还没有访问应用程序代码,但是一旦我得到它,我会尝试启用/禁用 Cookie 并看看会发生什么。
  • 访问了应用程序代码,发现确实 CookiesNever 是问题所在。我们能够将其更改为允许 CookiesAlways 并且它有效!

标签: jquery webview local-storage ios7 web-sql


【解决方案1】:

试试这个 cookie 策略设置:https://gist.github.com/steveriggins/6652508

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];

【讨论】:

    【解决方案2】:

    自从升级到 iOS7 后,存储在 localStorage 中的所有内容似乎在网页重新加载时都会被擦除。

    <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>
    

    【讨论】:

    • 谢谢,但它最终成为应用代码 Cookie 政策的问题。请参阅 russau 的回答。
    猜你喜欢
    • 1970-01-01
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多