Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 unable to access HTML5 localStorage, if Cookies is disabled

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

like image 997
san Avatar asked Sep 21 '13 11:09

san


1 Answers

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.

like image 149
gro Avatar answered Nov 08 '22 12:11

gro