admin管理员组

文章数量:1325408

I have an App that is pulling parts of a website into UIWebViews. Those pages use Local Storage to persist state, like last thing viewed and various settings, etc.

I see the UIWebViews local storage being created (via Web Inspector with device and App connected to debug machine) but then cleared after the App is shut down. The relevant pages work correctly on the main site in standard browsers and even Mobile Safari, but not in the UIWebViews?

I've been digging around and see some talk of changes to Local Storage cache with iOS6 but am not getting a clear sense of if this can work or not, and if so how to enable it?

Anyone out there have a definitive answer, before we have to switch to using cookies or do something on the server side?

Thanks.

I have an App that is pulling parts of a website into UIWebViews. Those pages use Local Storage to persist state, like last thing viewed and various settings, etc.

I see the UIWebViews local storage being created (via Web Inspector with device and App connected to debug machine) but then cleared after the App is shut down. The relevant pages work correctly on the main site in standard browsers and even Mobile Safari, but not in the UIWebViews?

I've been digging around and see some talk of changes to Local Storage cache with iOS6 but am not getting a clear sense of if this can work or not, and if so how to enable it?

Anyone out there have a definitive answer, before we have to switch to using cookies or do something on the server side?

Thanks.

Share Improve this question edited Aug 4, 2015 at 9:36 Cliff Ribaudo asked Oct 21, 2012 at 18:26 Cliff RibaudoCliff Ribaudo 9,0392 gold badges58 silver badges80 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

* UPDATE *
Definite iOS bug, reported as: #12546916
Not Fixed as of iOS: 8.3

UIWebView ignores WebKitStoreWebDataForBackup key when set in NSUserDefaults.

* Original Post *
This NSUserDefaults key became available in iOS 6:

WebKitStoreWebDataForBackup = YES

We set it at the top of our ApplicationDelegate like so:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"WebKitStoreWebDataForBackup"];

iOS 6 Release Notes discuss here: Release Notes. It's supposed to tell WebKit that UIWebView LocalStorage is not disposable and cause it to be placed in non-disposable location.

Clearly not working. iOS ignores WebKitStoreWebDataForBackup and deletes LocalStorage when the application shuts down or the page refreshes.

Using the Web Inspector during debugging it is possible to see local storage created, but then after App shut down and re-start it's gone.

The html/js page in question DOES work when viewed in Firefox, Chrome, Safari AND Mobile Safari, but NOT when the page is viewed in UIWebView.

本文标签: javascriptHTML 5 Local Storage Not Working In UIWebView on iOS 67 or 8Stack Overflow