How to open Database in Mobile Safari from JS loaded from disk
We have an iPhone application that is essentially a web site encapsulated in an app. This app loads the HTML and JS files from the local disk and interaction is done in JS.
However, with iOS 4.2, the JS has started receiving "SECURITY_ERR: DOM Exception 18" when opening a database, and as a result, our app doesn't work at all. The exact same file worked开发者_JAVA技巧 fine in prior versions of iOS and works fine when loaded from a web server.
Is there a way to configure iOS to permit JS running in a local file to access a database?
Thank you!
Kevin
I believe that you are exceeding the 5mb limit size for the Database.
At least that's the only way i can find to replicate that error message.
The browser normally prevents a runaway web application from using excessive local resources by setting limits on the size of each site’s database. When a database change would cause the database to exceed that limit, the user is notified and asked for permission to allow the database to grow further.
If you know that you are going to be filling the database with a lot of content, you should specify an ample size here. By so doing, the user is only asked for permission once when creating the database instead of every few megabytes as the database grows.
The browser may set limits on how large a value you can specify for this field, but the details of these limits are not yet fully defined.
http://developer.apple.com/library/safari/#documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html%23//apple_ref/doc/uid/TP40007256-CH3-SW2
I guess I should answer this question since I did finally get an answer from Apple Developer Support confessing this to be a bug in iOS4.
The specific problem is when you load a webView using [webView loadData...]. When loaded this way, webKit does not allow access to databases. If the same call is changed to use [webView loadRequest...] databases are permitted.
There is sample code to demonstrate the problem here: http://code.google.com/p/iui/source/browse/sandbox/hybrid/HybridiUI/Classes/HybridiUIAppDelegate.m
The same bug, by the way, exists in Google Chrome, which also uses webKit. When loading a web site from a local file in Chrome, databases and AJAX calls are forbidden, but when loading from a web server they are permitted.
精彩评论