代码之家  ›  专栏  ›  技术社区  ›  pilar1347

localStorage不再适用于iOS 7 WebView

  •  2
  • pilar1347  · 技术社区  · 12 年前

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

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

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

    2 回复  |  直到 12 年前
        1
  •  2
  •   russau    12 年前

    请从要点尝试此cookie策略设置: https://gist.github.com/steveriggins/6652508

    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
    
        2
  •  1
  •   Andrew    12 年前

    由于升级到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>