[webkit-help] How to get persistent html5 localStorage and webApplicationCache in Xcode?

Conti ewconti at gmail.com
Mon Sep 26 08:56:41 PDT 2011

I abandoned my desire to use websqldb - it just does not want to 
co-operate at all and I was unable to get any help from apple, 
stackoverflow, irc or webkit-help so I gave up.

I have localStorage and offline application cache working, and they are 
persistent to some degree - the data does persist while the app is 
running and even after the app is exited the localstorage data is 
retained on disk, but the problem is when the app is launched again it 
erases everything on disk and starts off blank. I need the offline data 
and localstorage data to persist long-term - across application launches 
and system reboots.

Here is some example code, hopefully someone can spare a few minutes to 
help me this time.

Xcode version is 4.2b7 this is an OS X app NOT iOS

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

     // Define some preferences
     WebPreferences *prefs = [webView preferences];
     [prefs setCacheModel:WebCacheModelPrimaryWebBrowser];
     [prefs setJavaEnabled:NO];
     [prefs setJavaScriptEnabled:YES];
     [prefs setJavaScriptCanOpenWindowsAutomatically:NO];
     [prefs setPlugInsEnabled:NO];
     [prefs setPrivateBrowsingEnabled:NO];
     [prefs setDefaultFontSize:16];
     [prefs setDefaultFixedFontSize:13];

     // Define some private preferences

     // Enable developer extras (web inspector)
     [prefs setDeveloperExtrasEnabled:YES];

     // Define application cache quota
     static const unsigned long long defaultTotalQuota = 10 * 1024 * 
1024; // 10MB
     static const unsigned long long defaultOriginQuota = 5 * 1024 * 
1024; // 5MB
     [prefs setApplicationCacheTotalQuota:defaultTotalQuota];
     [prefs setApplicationCacheDefaultOriginQuota:defaultOriginQuota];

     // Enable offline web application cache
     [prefs setOfflineWebApplicationCacheEnabled:YES];

     // Enable localStorage
     [prefs _setLocalStorageDatabasePath:@"~/Library/Application 
Support/My webView/LocalStorage/"];
     [prefs setLocalStorageEnabled:YES];

     // Load WebView Content

     //For remote connection
     NSString *url = @"http://someurl/somepath";
     NSURL *urlRequest = [NSURL URLWithString:url];

     //Request timeout
     NSInteger requestTimeout = 10;

     //Load request
     [[webView mainFrame] loadRequest:[NSURLRequest 


Thanks in advance,


More information about the webkit-help mailing list