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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With