Shazron Abdullah commented on CB-347:

With the help of Justin Harrison, the problem has been diagnosed. 

h2. Summary:

The error can be replicated only when on iOS 5.1, and upgrading an app to an 
updated version. On a new app install, you won't see this.

The bug is that the "WebDatabaseDirectory" and 
"WebKitLocalStorageDatabasePathPreferenceKey" values from NSUserDefaults (which 
are effectively read from Library/Preferences/[CFBundleIdentifier].plist) are 
incorrect, they refer to the previous version's app path. 

What's probably happening is, during an app upgrade, the app was moved/renamed 
to a new GUID, but these two plist values were not updated accordingly. The 
renaming of the app's application bundle to a new GUID might be new behaviour 
with iOS 5.1 app upgrades.

h2. Background:

The first clue we had was this error in the console log:
deny file-write-create 

The simplest explanation: permissions error, but what file? But all files in 
our app bundle we should have permissions to already.

On application launch, we printed out the value for 
"WebKitLocalStorageDatabasePathPreferenceKey" from NSUserDefaults, and compared 
it to the application's bundle path. The value for the key should reside 
entirely inside the application's bundle path, since this is where Webkit 
stores the localStorage database (similarly for WebSQL, the location for the 
database is through the "WebDatabaseDirectory" key).

Everytime we see the permissions error, we see that the value for 
"WebKitLocalStorageDatabasePathPreferenceKey" contains a path OUTSIDE of our 
application bundle. Bingo!

h2. Proposed Fix:

On app launch on an iOS 5.1 system, we test the keys "WebDatabaseDirectory" and 
"WebKitLocalStorageDatabasePathPreferenceKey" from NSUserDefaults, and if the 
paths fall outside of the application bundle's path - we change the paths to 
reflect the correct paths within the application bundle. 

We then commit the new path changes by reading then writing from the  
Library/Preferences/[CFBundleIdentifier].plist file, then synchronize 
NSUserDefaults to pick up the new changes.
> localStorage / SQLDatabase Error after App update
> -------------------------------------------------
>                 Key: CB-347
>                 URL: https://issues.apache.org/jira/browse/CB-347
>             Project: Apache Callback
>          Issue Type: Bug
>          Components: iOS
>    Affects Versions: 1.2.0, 1.3.0, 1.4.0, 1.5.0
>         Environment: iOS 5.01
> PhoneGap (Any version)
> Build.PhoneGap
>            Reporter: Urs Zimmermann
>            Assignee: Shazron Abdullah
>            Priority: Blocker
>              Labels: ios5.01, localstorage, phonegap, sqldatabase, websql
>         Attachments: WebKit-Prefs.zip
> Hello
> After I update my phonegap app containing values and dates in both 
> localStorage and SQLite database on iOS 5.1
> -> Call to window.openDatabase fails with "SECURITY_ERR: DOM Exception 18"
> -> Call to localStorage.setItem fails silently
> How to Reproduce:
> In a UIWebView, create a new DB or use localStorage from phonegap API
> Overwrite / update your app and open the same database or write to 
> localStorage
> Expected Results:
> We should see the data from the database and localStorage.
> Actual Results:
> Call to window.openDatabase fails with "SECURITY_ERR: DOM Exception 18"
> Call to localStorage.setItem fails silently
> References:
> https://groups.google.com/forum/#!topic/phonegap/egzXNrBRIbk/discussion
> https://groups.google.com/forum/#!topic/phonegap/jS2IVZcg8HI/discussion
> https://issues.apache.org/jira/browse/CB-330

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to