如果Cookie被禁用,iOS7无法访问HTML5 localStorage [英] iOS7 unable to access HTML5 localStorage, if Cookies is disabled

查看:330
本文介绍了如果Cookie被禁用,iOS7无法访问HTML5 localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS7上,当尝试通过JavaScript访问HTML5 localStorage对象时,停止执行Javascript。它在以前的iOS版本中正常工作。
当应用程序刚安装并启动时,应用程序运行完美。



为了禁用cookies,我使用了以下代码:

  [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever]; 

要访问localStorage,我使用了以下代码:

  CGRect rect = self.view.frame; 
UIWebView * webView = [[UIWebView alloc] initWithFrame:rect];
[self.view addSubview:webView];
[webView loadHTMLString:@< script> alert('hello world'); alert(localStorage);< / script& baseURL:nil]



我已经浏览了iOS7文档,但找不到任何与此问题相关的更新。有没有人面对这个?请分享任何有关这方面的信息,将是非常有益的。此问题的任何解决方法?



感谢

解决方案

较旧的帖子,但fwiw ...



不确定是否遇到此问题。在使用iOS6 / 7的几个项目上使用了localStorage,有和没有cookie。



loadHTMLString看起来有点特别的...所以我试试这个...

  [webView stringByEvaluatingJavaScriptFromString:@alert('hello world'); alert(localStorage); 

...工作正常,并显示localStorage对象的预期,禁用Cookie。 p>

在sim和设备上测试,iOS7。


On iOS7, while trying to access HTML5 localStorage object via JavaScript, stops execution of Javascript. It works correctly in previous iOS versions. The app runs perfectly when the app is freshly installed and launched. But then, I close the app and launch again, it does not work and fails on accessing localStorage.

To disable cookies, I have used below code:

[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyNever];

To access localStorage, I have used below code:

CGRect rect = self.view.frame;
UIWebView* webView = [[UIWebView alloc] initWithFrame:rect];
[self.view addSubview:webView];
[webView loadHTMLString:@"<script>alert('hello world');alert(localStorage);</script>" baseURL:nil]

I have gone through the iOS7 docs but could not find any update related to this issue. Has anyone faced this too? Please share any information regarding this, would be very helpful. Any workarounds for this?

Thanks

解决方案

Granted this is an older post, but fwiw ...

Not sure if I have experienced this issue. Have used localStorage with and without cookies on several projects using iOS6/7.

The loadHTMLString provided looks a little peculiar to me ... so I tried this instead...

    [webView stringByEvaluatingJavaScriptFromString:@"alert('hello world');alert(localStorage);"];

... which worked fine, and showed the localStorage object as expected, with cookies disabled.

Tested in sim and on device, iOS7.

这篇关于如果Cookie被禁用,iOS7无法访问HTML5 localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆