views:

439

answers:

3

I am using UIWebView in a regular Objective-C iPhone App. Web pages displayed in the UIWebView are writing to a HTML5 client-side SQL database via javascript. I would like to open this database for reading and writing from the iPhone App. Is this possible? and if so, how do I find the database and can I use the SQLite framework to open them?

+1  A: 

The HTML5 database lives outside your app's sandbox and can't be accessed directly. If you have control of the web pages being displayed in the UIWebView you can build a relatively simple javascript bridge to fetch the contents and insert them into your own SQLite DB.

Kirk van Gorkom
Thank you Kirk and Squeegy. I will certainly use the Javascript bridge and I think I may simplify things by using key-value storage (localStorage object).
Pete Thompson
+3  A: 

I don't think its exposed in this way.

First, I don't think UIWebViews will have a client side database that persists across multiple sessions (although it might, I haven't tested it). And second, it certainly doesn't give you direct access to the SQLite database file itself.

Your best bet would be call javascript into the webview with

[webView stringByEvaluatingJavascriptFromString:@"mySqlQueryingFunction()"]

letting javascript access the database for you.

Squeegy
A: 

Old question but I found this while Googling on the subject and thought I'd update it with the solution.

The localstorage databases are sqlite databases and are stored in <Application_Home>/Library/WebKit/LocalStorage and the database for your app will be something like file__0.localstorage

You can get the path to the file with something like this:

NSString* fullPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/WebKit/LocalStorage/file__0.localstorage"];

Hope this helps anyone else who's looking into this.

Ed Anuff