Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML 5 Local Storage Not Working In UIWebView on iOS 6, 7 or 8

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.

like image 825
Cliff Ribaudo Avatar asked Oct 21 '12 18:10

Cliff Ribaudo


1 Answers

* 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.

like image 63
Cliff Ribaudo Avatar answered Oct 16 '22 20:10

Cliff Ribaudo