开发者

Can I open an HTML5 client-side database via an iPhone App (objective-C)?

I am using UIW开发者_C百科ebView 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?


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.


The SQLite databases used by the UIWebView's WebKit instance are actually in <Application_Home>/Library/WebKit/LocalStorage/file__0/, e.g. 0000000000000001.db.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜