Apache Cordova
  1. Apache Cordova
  2. CB-347

localStorage / SQLDatabase Error after App update

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.6.0, 1.6.1
    • Fix Version/s: 1.7.0
    • Component/s: iOS
    • Environment:

      iOS 5.01
      PhoneGap (Any version)
      Build.PhoneGap

      Description

      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

      1. WebKit-Prefs.zip
        0.9 kB
        Shazron Abdullah

        Issue Links

          Activity

          Hide
          Shazron Abdullah added a comment -

          See linked issue - Apple has decided window.localStorage is not guaranteed to be persistent anymore. Workaround being worked on.

          Show
          Shazron Abdullah added a comment - See linked issue - Apple has decided window.localStorage is not guaranteed to be persistent anymore. Workaround being worked on.
          Hide
          Shazron Abdullah added a comment -

          Looks like there is a NSUserDefaults key "WebKitLocalStorageDatabasePathPreferenceKey" that points to the old db: http://stackoverflow.com/questions/9679163/why-does-clearing-nsuserdefaults-cause-exc-crash-later-when-creating-a-uiwebview

          Show
          Shazron Abdullah added a comment - Looks like there is a NSUserDefaults key "WebKitLocalStorageDatabasePathPreferenceKey" that points to the old db: http://stackoverflow.com/questions/9679163/why-does-clearing-nsuserdefaults-cause-exc-crash-later-when-creating-a-uiwebview
          Hide
          Shazron Abdullah added a comment - - edited

          More WebKit keys in Library/Preferences/CFBundleIdentifier.plist where CFBundleIdentifier is the CFBundleIdentifier value in your app's Info.plist

          Show
          Shazron Abdullah added a comment - - edited More WebKit keys in Library/Preferences/ CFBundleIdentifier .plist where CFBundleIdentifier is the CFBundleIdentifier value in your app's Info.plist
          Hide
          Shazron Abdullah added a comment -

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

          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.

          Background:

          The first clue we had was this error in the console log:
          deny file-write-create /private/var/mobile/Applications/43A38BD0-439A-4998-A51D-110C6E05AF7C

          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!

          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.

          Show
          Shazron Abdullah added a comment - With the help of Justin Harrison, the problem has been diagnosed. 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. Background: The first clue we had was this error in the console log: deny file-write-create /private/var/mobile/Applications/43A38BD0-439A-4998-A51D-110C6E05AF7C 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! 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.
          Hide
          Filip Maj added a comment -

          This is probably one of the most epic bugs / solutions I've come across in this project. Nice work Shaz!

          Show
          Filip Maj added a comment - This is probably one of the most epic bugs / solutions I've come across in this project. Nice work Shaz!
          Hide
          Urs Zimmermann added a comment -

          Shazron you are the man! Thank you for your analysis.

          Unfortunately I am a phonegap/cordova user and not an iOS developper.

          Do I get this right: Your proposed fix would be a solution for cordova itself? When would that be ready? (My app update is due in the next week...)

          Show
          Urs Zimmermann added a comment - Shazron you are the man! Thank you for your analysis. Unfortunately I am a phonegap/cordova user and not an iOS developper. Do I get this right: Your proposed fix would be a solution for cordova itself? When would that be ready? (My app update is due in the next week...)
          Hide
          Shazron Abdullah added a comment -

          If it works, this will be incorporated into Cordova 1.6.0, and also the plugin for older versions (see CB-330). We're targeting a RC release on Mar 26th.
          The proposed fix hasn't been fully tested yet, hopefully after testing it can be accepted.

          Show
          Shazron Abdullah added a comment - If it works, this will be incorporated into Cordova 1.6.0, and also the plugin for older versions (see CB-330 ). We're targeting a RC release on Mar 26th. The proposed fix hasn't been fully tested yet, hopefully after testing it can be accepted.
          Hide
          Shazron Abdullah added a comment -

          I should mention that the bulk of the findings are due to the diligence of Justin Harrison

          Show
          Shazron Abdullah added a comment - I should mention that the bulk of the findings are due to the diligence of Justin Harrison
          Hide
          Shazron Abdullah added a comment -

          Filed a bug with Apple, you should too, to raise the visibility of this issue.

          Reported to Apple: rdar://11081309

          Copied here: http://openradar.appspot.com/radar?id=1608403

          Show
          Shazron Abdullah added a comment - Filed a bug with Apple, you should too, to raise the visibility of this issue. Reported to Apple: rdar://11081309 Copied here: http://openradar.appspot.com/radar?id=1608403
          Hide
          Samuel Michelot added a comment -

          Great work!
          I also reported the bug on bugreport.apple.com

          Show
          Samuel Michelot added a comment - Great work! I also reported the bug on bugreport.apple.com
          Hide
          Shazron Abdullah added a comment -

          This bug is fixed through the updated plugin I just attached to CB-330. Please test.

          Show
          Shazron Abdullah added a comment - This bug is fixed through the updated plugin I just attached to CB-330 . Please test.
          Hide
          Daniel added a comment -

          I tried installing an app using localstorage (let's call it v1) without the CB-330 fix, then upgraded to a new version of the app with the CB-330 fix (v2).

          The data from v1 is still visible in v2. Now I add some additional data, I kill the app and restart it. The old data is still there, however the newly added data is gone.

          I don't understand why this happens. Perhaps because the code is copying the backup db over the newly modified version?

          Show
          Daniel added a comment - I tried installing an app using localstorage (let's call it v1) without the CB-330 fix, then upgraded to a new version of the app with the CB-330 fix (v2). The data from v1 is still visible in v2. Now I add some additional data, I kill the app and restart it. The old data is still there, however the newly added data is gone. I don't understand why this happens. Perhaps because the code is copying the backup db over the newly modified version?
          Hide
          Mike Newman added a comment -

          Thanks alot for the fix!

          It seems to allow my app access to the database after an update finally, but I still get the "SECURITY_ERR: DOM Exception 18" database access error when the plugin applies the "verifyAndFixDatabaseLocations" function on the first install of the app over my old app. Once the locations of the databases are fixed and the app has been restarted, it works perfectly, but it seems as though the locations aren't being applied until the app is restarted.

          Any suggestions as to how this can be fixed? I'd really like to finish the fix to my app ASAP.

          Thanks!

          Show
          Mike Newman added a comment - Thanks alot for the fix! It seems to allow my app access to the database after an update finally, but I still get the "SECURITY_ERR: DOM Exception 18" database access error when the plugin applies the "verifyAndFixDatabaseLocations" function on the first install of the app over my old app. Once the locations of the databases are fixed and the app has been restarted, it works perfectly, but it seems as though the locations aren't being applied until the app is restarted. Any suggestions as to how this can be fixed? I'd really like to finish the fix to my app ASAP. Thanks!
          Hide
          Shazron Abdullah added a comment -

          @daniel seems like it - more like a CB-330 case (re-opened)

          @mike seems like a timing issue - in the instructions, try applying the code first thing in applicationDidFinishLaunching instead of webviewDidStartLoad. will try to fix

          I'm away today - will get to your issues tomorrow.

          Show
          Shazron Abdullah added a comment - @daniel seems like it - more like a CB-330 case (re-opened) @mike seems like a timing issue - in the instructions, try applying the code first thing in applicationDidFinishLaunching instead of webviewDidStartLoad. will try to fix I'm away today - will get to your issues tomorrow.
          Hide
          Mike Newman added a comment - - edited

          Yep, I can confirm that it now works (at least for me) without restarting now that the database locations are changed during applicationDidFinishLaunching.

          Thanks alot for the suggestion!

          Show
          Mike Newman added a comment - - edited Yep, I can confirm that it now works (at least for me) without restarting now that the database locations are changed during applicationDidFinishLaunching. Thanks alot for the suggestion!
          Hide
          Dave Orchard added a comment -

          I think this implementation is still incomplete. After upgrading an app from <5.1 to 5.1, the OS will be 5.1 but the old location should be used. The check for location should allow the old. If the data exists, migrate it as well as update the plist entries.

          Show
          Dave Orchard added a comment - I think this implementation is still incomplete. After upgrading an app from <5.1 to 5.1, the OS will be 5.1 but the old location should be used. The check for location should allow the old. If the data exists, migrate it as well as update the plist entries.
          Hide
          Shazron Abdullah added a comment -

          @Dave Orchard it is my understanding that in 5.1, the OS would move everything to the new location, is that not the case? Or is this only for new dbs in 5.1

          Show
          Shazron Abdullah added a comment - @Dave Orchard it is my understanding that in 5.1, the OS would move everything to the new location, is that not the case? Or is this only for new dbs in 5.1
          Hide
          Shazron Abdullah added a comment -

          @Dave Orchard - shouldn't matter what the OS does, I'll add these checks to be safe.

          Show
          Shazron Abdullah added a comment - @Dave Orchard - shouldn't matter what the OS does, I'll add these checks to be safe.
          Hide
          Dave Orchard added a comment -

          We are finding on when xcode runs the app on simulator or device, the OS seems to move things. OTA install to device does not appear to move the files.

          Show
          Dave Orchard added a comment - We are finding on when xcode runs the app on simulator or device, the OS seems to move things. OTA install to device does not appear to move the files.
          Hide
          Suhail Dutta added a comment -

          Got the following back from Apple

          This is a follow up to Bug ID# 11105407. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 11063678. The original bug number being used to track this duplicate issue can be found in the Related Problem section of your bug report's Problem Detail view.

          Shazron, was the bug id for the one you filed? They're taking a look at it.

          Show
          Suhail Dutta added a comment - Got the following back from Apple This is a follow up to Bug ID# 11105407. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 11063678. The original bug number being used to track this duplicate issue can be found in the Related Problem section of your bug report's Problem Detail view. Shazron, was the bug id for the one you filed? They're taking a look at it.
          Hide
          Shazron Abdullah added a comment -

          @Suhail no my bug id is rdar://11081309 but I know there are dupes at rdar://11081647 and rdar://10296507 as well.

          So now we have these 5 dupes (at least):
          rdar://11081309
          rdar://11081647
          rdar://10296507
          rdar://11105407
          rdar://11063678

          Show
          Shazron Abdullah added a comment - @Suhail no my bug id is rdar://11081309 but I know there are dupes at rdar://11081647 and rdar://10296507 as well. So now we have these 5 dupes (at least): rdar://11081309 rdar://11081647 rdar://10296507 rdar://11105407 rdar://11063678
          Show
          Shazron Abdullah added a comment - Issue brought up in CB-330 - https://issues.apache.org/jira/browse/CB-330?focusedCommentId=13255938&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13255938 Fix updated in 1.6.1 - http://git-wip-us.apache.org/repos/asf?p=incubator-cordova-ios.git;a=commit;h=d358ab2b
          Show
          Shazron Abdullah added a comment - Blog post summarizing this issue: http://phonegap.com/2012/04/18/ios-5-1-and-the-embedded-uiwebview-with-cordova/
          Hide
          Roy Yang added a comment - - edited

          I currently have Phonegap 1.6.1 and this bug is not fully resolved for me. Here's the flow:

          1. Distribute the app wirelessly as an Enterprise app.
          2. Data gets stored in localStorage
          3. Distribute an update to the app wirelessly
          4. The first time the user goes into the app, all of their data is gone. I use weinre and confirm that the localStorage shows up as empty.
          5. The user must close the app completely, reopen the app and then the localStorage is back.

          EDIT: If in step 4, a user starts putting in new data, it will get wiped out in step 5. Is there a different flow for the first time an app is updated because I would think it would copy over what's in the persistent storage back to the localStorage.

          Show
          Roy Yang added a comment - - edited I currently have Phonegap 1.6.1 and this bug is not fully resolved for me. Here's the flow: 1. Distribute the app wirelessly as an Enterprise app. 2. Data gets stored in localStorage 3. Distribute an update to the app wirelessly 4. The first time the user goes into the app, all of their data is gone. I use weinre and confirm that the localStorage shows up as empty. 5. The user must close the app completely, reopen the app and then the localStorage is back. EDIT: If in step 4, a user starts putting in new data, it will get wiped out in step 5. Is there a different flow for the first time an app is updated because I would think it would copy over what's in the persistent storage back to the localStorage.
          Hide
          Shazron Abdullah added a comment -

          @Roy, can you go to CB-330 and download and run the diagnostic plugin. How I did it is the only solution that I can think of - unless you have a *solution* to suggest you will have to run this plugin so I can get more clues to the problem.

          Show
          Shazron Abdullah added a comment - @Roy, can you go to CB-330 and download and run the diagnostic plugin. How I did it is the only solution that I can think of - unless you have a * solution * to suggest you will have to run this plugin so I can get more clues to the problem.
          Hide
          Roy Yang added a comment -

          @shazron

          Hi Shazron, here is the dump when I push a new version to the iPad through xCode:

          2012-04-24 16:28:37.251 GreenSolutions[1382:707] Multi-tasking -> Device: YES, App: YES
          2012-04-24 16:28:39.036 GreenSolutions[1382:707] ===Start CDVLocalStorageDiagnostics==========
          2012-04-24 16:28:39.038 GreenSolutions[1382:707] iOS version: 5.1
          2012-04-24 16:28:39.039 GreenSolutions[1382:707] =============================================
          2012-04-24 16:28:39.040 GreenSolutions[1382:707] Printing list of backup info.
          2012-04-24 16:28:39.041 GreenSolutions[1382:707] --------------------------------------
          2012-04-24 16:28:39.042 GreenSolutions[1382:707] Label: localStorage database
          2012-04-24 16:28:39.046 GreenSolutions[1382:707] shouldBackup: NO shouldRestore: NO
          2012-04-24 16:28:39.047 GreenSolutions[1382:707] Original: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches/file__0.localstorage Exists?: YES
          2012-04-24 16:28:39.048 GreenSolutions[1382:707] Backup: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Documents/Backups/localstorage.appdata.db Exists?: YES
          2012-04-24 16:28:39.049 GreenSolutions[1382:707] --------------------------------------
          2012-04-24 16:28:39.050 GreenSolutions[1382:707] Label: websql main database
          2012-04-24 16:28:39.051 GreenSolutions[1382:707] shouldBackup: NO shouldRestore: NO
          2012-04-24 16:28:39.053 GreenSolutions[1382:707] Original: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches/Databases.db Exists?: NO
          2012-04-24 16:28:39.054 GreenSolutions[1382:707] Backup: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Documents/Backups/websqlmain.appdata.db Exists?: NO
          2012-04-24 16:28:39.055 GreenSolutions[1382:707] --------------------------------------
          2012-04-24 16:28:39.056 GreenSolutions[1382:707] Label: websql databases
          2012-04-24 16:28:39.057 GreenSolutions[1382:707] shouldBackup: NO shouldRestore: NO
          2012-04-24 16:28:39.058 GreenSolutions[1382:707] Original: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches/file__0 Exists?: NO
          2012-04-24 16:28:39.059 GreenSolutions[1382:707] Backup: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Documents/Backups/websqldbs.appdata.db Exists?: NO
          2012-04-24 16:28:39.060 GreenSolutions[1382:707] =============================================
          2012-04-24 16:28:39.060 GreenSolutions[1382:707] Printing folder locations, check for existence.
          2012-04-24 16:28:39.061 GreenSolutions[1382:707] Path /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches exists?: YES
          2012-04-24 16:28:39.063 GreenSolutions[1382:707] Path /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/WebKit exists?: NO
          2012-04-24 16:28:39.064 GreenSolutions[1382:707] =============================================
          2012-04-24 16:28:39.065 GreenSolutions[1382:707] Checking plist /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Preferences/com.fsgi.GreenSolutions.plist for WebKit keys.
          2012-04-24 16:28:39.066 GreenSolutions[1382:707] Key: WebKitLocalStorageDatabasePathPreferenceKey Value: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches
          2012-04-24 16:28:39.067 GreenSolutions[1382:707] Key: WebDatabaseDirectory Value: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches
          2012-04-24 16:28:39.068 GreenSolutions[1382:707] ===End CDVLocalStorageDiagnostics============

          How do I get a dump of what happens inside the app when I do an over the air update? I'm no longer in xCode so I don't know where to get those NSLog messages. I have weinre - can I use that to output?

          Show
          Roy Yang added a comment - @shazron Hi Shazron, here is the dump when I push a new version to the iPad through xCode: 2012-04-24 16:28:37.251 GreenSolutions [1382:707] Multi-tasking -> Device: YES, App: YES 2012-04-24 16:28:39.036 GreenSolutions [1382:707] ===Start CDVLocalStorageDiagnostics========== 2012-04-24 16:28:39.038 GreenSolutions [1382:707] iOS version: 5.1 2012-04-24 16:28:39.039 GreenSolutions [1382:707] ============================================= 2012-04-24 16:28:39.040 GreenSolutions [1382:707] Printing list of backup info. 2012-04-24 16:28:39.041 GreenSolutions [1382:707] -------------------------------------- 2012-04-24 16:28:39.042 GreenSolutions [1382:707] Label: localStorage database 2012-04-24 16:28:39.046 GreenSolutions [1382:707] shouldBackup: NO shouldRestore: NO 2012-04-24 16:28:39.047 GreenSolutions [1382:707] Original: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches/file__0.localstorage Exists?: YES 2012-04-24 16:28:39.048 GreenSolutions [1382:707] Backup: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Documents/Backups/localstorage.appdata.db Exists?: YES 2012-04-24 16:28:39.049 GreenSolutions [1382:707] -------------------------------------- 2012-04-24 16:28:39.050 GreenSolutions [1382:707] Label: websql main database 2012-04-24 16:28:39.051 GreenSolutions [1382:707] shouldBackup: NO shouldRestore: NO 2012-04-24 16:28:39.053 GreenSolutions [1382:707] Original: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches/Databases.db Exists?: NO 2012-04-24 16:28:39.054 GreenSolutions [1382:707] Backup: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Documents/Backups/websqlmain.appdata.db Exists?: NO 2012-04-24 16:28:39.055 GreenSolutions [1382:707] -------------------------------------- 2012-04-24 16:28:39.056 GreenSolutions [1382:707] Label: websql databases 2012-04-24 16:28:39.057 GreenSolutions [1382:707] shouldBackup: NO shouldRestore: NO 2012-04-24 16:28:39.058 GreenSolutions [1382:707] Original: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches/file__0 Exists?: NO 2012-04-24 16:28:39.059 GreenSolutions [1382:707] Backup: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Documents/Backups/websqldbs.appdata.db Exists?: NO 2012-04-24 16:28:39.060 GreenSolutions [1382:707] ============================================= 2012-04-24 16:28:39.060 GreenSolutions [1382:707] Printing folder locations, check for existence. 2012-04-24 16:28:39.061 GreenSolutions [1382:707] Path /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches exists?: YES 2012-04-24 16:28:39.063 GreenSolutions [1382:707] Path /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/WebKit exists?: NO 2012-04-24 16:28:39.064 GreenSolutions [1382:707] ============================================= 2012-04-24 16:28:39.065 GreenSolutions [1382:707] Checking plist /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Preferences/com.fsgi.GreenSolutions.plist for WebKit keys. 2012-04-24 16:28:39.066 GreenSolutions [1382:707] Key: WebKitLocalStorageDatabasePathPreferenceKey Value: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches 2012-04-24 16:28:39.067 GreenSolutions [1382:707] Key: WebDatabaseDirectory Value: /var/mobile/Applications/9A2A86F2-E827-4339-8C12-8903C814064F/Library/Caches 2012-04-24 16:28:39.068 GreenSolutions [1382:707] ===End CDVLocalStorageDiagnostics============ How do I get a dump of what happens inside the app when I do an over the air update? I'm no longer in xCode so I don't know where to get those NSLog messages. I have weinre - can I use that to output?
          Hide
          Shazron Abdullah added a comment -

          Thanks @Roy I'll examine the log. You can make your users install the iPhone Configuration Utility http://support.apple.com/kb/DL1465 to access the console (select your tethered device, see screenshot: http://cl.ly/G6vW).

          I could update the plugin to paste the diagnostic log into the pasteboard as well if you'd like, so they can paste it into an e-mail.

          Show
          Shazron Abdullah added a comment - Thanks @Roy I'll examine the log. You can make your users install the iPhone Configuration Utility http://support.apple.com/kb/DL1465 to access the console (select your tethered device, see screenshot: http://cl.ly/G6vW ). I could update the plugin to paste the diagnostic log into the pasteboard as well if you'd like, so they can paste it into an e-mail.
          Hide
          Roy Yang added a comment - - edited

          @shazron

          Ah I see what the issue is. I looked at the console in xCode organizer. It appears to be the same error that @angelo has in CB330. Should I move my comments there to consolidate with that same issue?

          It appears that the application gets a new ID or there is an inconsistency in the ID and I'm getting deny file-write-create /private/var/mobile/Applications/F2BE3CCA-AB36-4498-A7B0-81CB6D643512. On subsequent closing down and reopening of the app, I no longer see that message.

          Below is after I wireless download an enterprise app. The first time the localStorage never initializes, need to close the app and reopen to get the right localStorage

          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: ===Start CDVLocalStorageDiagnostics==========
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: iOS version: 5.1
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: =============================================
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Printing list of backup info.
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: --------------------------------------
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Label: localStorage database
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: shouldBackup: YES shouldRestore: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Original: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches/file__0.localstorage Exists?: YES
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Backup: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Documents/Backups/localstorage.appdata.db Exists?: YES
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: --------------------------------------
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Label: websql main database
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: shouldBackup: NO shouldRestore: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Original: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches/Databases.db Exists?: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Backup: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Documents/Backups/websqlmain.appdata.db Exists?: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: --------------------------------------
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Label: websql databases
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: shouldBackup: NO shouldRestore: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Original: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches/file__0 Exists?: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Backup: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Documents/Backups/websqldbs.appdata.db Exists?: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: =============================================
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Printing folder locations, check for existence.
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Path /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches exists?: YES
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Path /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/WebKit exists?: NO
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: =============================================
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Checking plist /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Preferences/com.fsgi.GreenSolutions.plist for WebKit keys.
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Key: WebKitLocalStorageDatabasePathPreferenceKey Value: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: Key: WebDatabaseDirectory Value: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches
          Apr 24 16:50:45 unknown GreenSolutions[1451] <Warning>: ===End CDVLocalStorageDiagnostics============
          >
          Apr 24 16:50:47 unknown sandboxd[1452] <Notice>: GreenSolutions(1451) deny file-write-create /private/var/mobile/Applications/F2BE3CCA-AB36-4498-A7B0-81CB6D643512

          Show
          Roy Yang added a comment - - edited @shazron Ah I see what the issue is. I looked at the console in xCode organizer. It appears to be the same error that @angelo has in CB330. Should I move my comments there to consolidate with that same issue? It appears that the application gets a new ID or there is an inconsistency in the ID and I'm getting deny file-write-create /private/var/mobile/Applications/F2BE3CCA-AB36-4498-A7B0-81CB6D643512. On subsequent closing down and reopening of the app, I no longer see that message. Below is after I wireless download an enterprise app. The first time the localStorage never initializes, need to close the app and reopen to get the right localStorage Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: ===Start CDVLocalStorageDiagnostics========== Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: iOS version: 5.1 Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: ============================================= Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Printing list of backup info. Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: -------------------------------------- Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Label: localStorage database Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: shouldBackup: YES shouldRestore: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Original: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches/file__0.localstorage Exists?: YES Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Backup: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Documents/Backups/localstorage.appdata.db Exists?: YES Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: -------------------------------------- Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Label: websql main database Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: shouldBackup: NO shouldRestore: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Original: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches/Databases.db Exists?: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Backup: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Documents/Backups/websqlmain.appdata.db Exists?: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: -------------------------------------- Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Label: websql databases Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: shouldBackup: NO shouldRestore: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Original: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches/file__0 Exists?: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Backup: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Documents/Backups/websqldbs.appdata.db Exists?: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: ============================================= Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Printing folder locations, check for existence. Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Path /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches exists?: YES Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Path /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/WebKit exists?: NO Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: ============================================= Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Checking plist /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Preferences/com.fsgi.GreenSolutions.plist for WebKit keys. Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Key: WebKitLocalStorageDatabasePathPreferenceKey Value: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: Key: WebDatabaseDirectory Value: /var/mobile/Applications/15D854F8-CAD6-4E91-8665-349609846668/Library/Caches Apr 24 16:50:45 unknown GreenSolutions [1451] <Warning>: ===End CDVLocalStorageDiagnostics============ > Apr 24 16:50:47 unknown sandboxd [1452] <Notice>: GreenSolutions(1451) deny file-write-create /private/var/mobile/Applications/F2BE3CCA-AB36-4498-A7B0-81CB6D643512
          Hide
          Shazron Abdullah added a comment -

          This is quite strange, let me explain.

          The hypothesis is that the UIWebView grabs the location of the databases from the .plist, and from the report it shows that paths in the .plist are correct (path 15D8). At 16:50:47, it reports a security error when trying to write to path F2BE, which should never happen if the paths were read from the .plist.

          The fix was to correct these .plist values if they were incorrect. In this case, 1. either the path was already correct, or 2. the path was fixed by the plugin. Was there anything before this log that showed a fix was applied at all, or is this the complete log?

          Show
          Shazron Abdullah added a comment - This is quite strange, let me explain. The hypothesis is that the UIWebView grabs the location of the databases from the .plist, and from the report it shows that paths in the .plist are correct (path 15D8). At 16:50:47, it reports a security error when trying to write to path F2BE, which should never happen if the paths were read from the .plist. The fix was to correct these .plist values if they were incorrect. In this case, 1. either the path was already correct, or 2. the path was fixed by the plugin. Was there anything before this log that showed a fix was applied at all, or is this the complete log?
          Hide
          Roy Yang added a comment -

          I ran it again and here is the whole log. Somewhere along the line, the IDs do get messed up:

          >
          Apr 24 17:39:32 unknown GreenSolutions[1518] <Warning>: Multi-tasking -> Device: YES, App: YES
          Apr 24 17:39:32 unknown GreenSolutions[1518] <Warning>: Fix applied for database locations?: YES
          Apr 24 17:39:32 unknown kernel[0] <Debug>: launchd[1518] Builtin profile: container (sandbox)
          Apr 24 17:39:32 unknown kernel[0] <Debug>: launchd[1518] Container: /private/var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2 [69] (sandbox)
          >
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: ===Start CDVLocalStorageDiagnostics==========
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: iOS version: 5.1
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: =============================================
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Printing list of backup info.
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: --------------------------------------
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Label: localStorage database
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: shouldBackup: NO shouldRestore: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Original: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches/file__0.localstorage Exists?: YES
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Backup: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Documents/Backups/localstorage.appdata.db Exists?: YES
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: --------------------------------------
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Label: websql main database
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: shouldBackup: NO shouldRestore: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Original: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches/Databases.db Exists?: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Backup: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Documents/Backups/websqlmain.appdata.db Exists?: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: --------------------------------------
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Label: websql databases
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: shouldBackup: NO shouldRestore: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Original: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches/file__0 Exists?: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Backup: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Documents/Backups/websqldbs.appdata.db Exists?: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: =============================================
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Printing folder locations, check for existence.
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Path /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches exists?: YES
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Path /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/WebKit exists?: NO
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: =============================================
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Checking plist /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Preferences/com.fsgi.GreenSolutions.plist for WebKit keys.
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Key: WebKitLocalStorageDatabasePathPreferenceKey Value: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: Key: WebDatabaseDirectory Value: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches
          Apr 24 17:39:33 unknown GreenSolutions[1518] <Warning>: ===End CDVLocalStorageDiagnostics============
          Apr 24 17:39:33 unknown sandboxd[1520] <Notice>: GreenSolutions(1518) deny file-write-create /private/var/mobile/Applications/D13AF97A-63C0-4F35-AC96-F214AB08E5CB
          >
          Apr 24 17:39:35 unknown sandboxd[1520] <Notice>: GreenSolutions(1518) deny file-write-create /private/var/mobile/Applications/D13AF97A-63C0-4F35-AC96-F214AB08E5CB
          >

          Show
          Roy Yang added a comment - I ran it again and here is the whole log. Somewhere along the line, the IDs do get messed up: > Apr 24 17:39:32 unknown GreenSolutions [1518] <Warning>: Multi-tasking -> Device: YES, App: YES Apr 24 17:39:32 unknown GreenSolutions [1518] <Warning>: Fix applied for database locations?: YES Apr 24 17:39:32 unknown kernel [0] <Debug>: launchd [1518] Builtin profile: container (sandbox) Apr 24 17:39:32 unknown kernel [0] <Debug>: launchd [1518] Container: /private/var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2 [69] (sandbox) > Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: ===Start CDVLocalStorageDiagnostics========== Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: iOS version: 5.1 Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: ============================================= Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Printing list of backup info. Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: -------------------------------------- Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Label: localStorage database Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: shouldBackup: NO shouldRestore: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Original: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches/file__0.localstorage Exists?: YES Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Backup: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Documents/Backups/localstorage.appdata.db Exists?: YES Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: -------------------------------------- Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Label: websql main database Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: shouldBackup: NO shouldRestore: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Original: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches/Databases.db Exists?: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Backup: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Documents/Backups/websqlmain.appdata.db Exists?: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: -------------------------------------- Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Label: websql databases Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: shouldBackup: NO shouldRestore: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Original: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches/file__0 Exists?: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Backup: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Documents/Backups/websqldbs.appdata.db Exists?: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: ============================================= Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Printing folder locations, check for existence. Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Path /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches exists?: YES Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Path /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/WebKit exists?: NO Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: ============================================= Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Checking plist /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Preferences/com.fsgi.GreenSolutions.plist for WebKit keys. Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Key: WebKitLocalStorageDatabasePathPreferenceKey Value: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: Key: WebDatabaseDirectory Value: /var/mobile/Applications/D91A5D14-C147-4946-BEE1-26470BC39FD2/Library/Caches Apr 24 17:39:33 unknown GreenSolutions [1518] <Warning>: ===End CDVLocalStorageDiagnostics============ Apr 24 17:39:33 unknown sandboxd [1520] <Notice>: GreenSolutions(1518) deny file-write-create /private/var/mobile/Applications/D13AF97A-63C0-4F35-AC96-F214AB08E5CB > Apr 24 17:39:35 unknown sandboxd [1520] <Notice>: GreenSolutions(1518) deny file-write-create /private/var/mobile/Applications/D13AF97A-63C0-4F35-AC96-F214AB08E5CB >
          Hide
          Shazron Abdullah added a comment -

          Thanks, this makes it clearer. The CB-347 fix was applied, and this is confirmed by printing out the .plist value, but UIWebView still picks up the old paths.

          So either:
          1. UIWebView is using another location for the .plist location and/or it's cached
          2. The patch was applied too late

          I'm leaning towards #2. I'm going to give the code a once-over and step through the timing of events.

          Show
          Shazron Abdullah added a comment - Thanks, this makes it clearer. The CB-347 fix was applied, and this is confirmed by printing out the .plist value, but UIWebView still picks up the old paths. So either: 1. UIWebView is using another location for the .plist location and/or it's cached 2. The patch was applied too late I'm leaning towards #2. I'm going to give the code a once-over and step through the timing of events.
          Hide
          Shazron Abdullah added a comment -

          Looking at the code, the fix is applied here:
          https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVViewController.m#L167

          But the page is loaded here:
          https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVViewController.m#L197

          There shouldn't be security errors before the page is loaded since there would be no calls to localStorage/WebSQL.

          So the sequence of events appears to be correct, and they should occur synchronously. The only thing is, the UIWebView is created first before either of the code blocks, and perhaps during the UIWebView initialization, it picks up the .plist values.

          In my testing, and probably in other users' testing when they tested the patch, this UIWebView initialization of .plist values happens after the patch is applied (a fluke of timing), so everything appears ok - while in your case, it is the opposite.

          The evidence points to the UIWebView picking up the .plist locations after it is instantiated (which makes sense if one was to design the class), but before a request is handled.

          The fix for this would be to apply the patch before the UIWebView is instantiated.

          Show
          Shazron Abdullah added a comment - Looking at the code, the fix is applied here: https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVViewController.m#L167 But the page is loaded here: https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVViewController.m#L197 There shouldn't be security errors before the page is loaded since there would be no calls to localStorage/WebSQL. So the sequence of events appears to be correct, and they should occur synchronously. The only thing is, the UIWebView is created first before either of the code blocks, and perhaps during the UIWebView initialization, it picks up the .plist values. In my testing, and probably in other users' testing when they tested the patch, this UIWebView initialization of .plist values happens after the patch is applied (a fluke of timing), so everything appears ok - while in your case, it is the opposite. The evidence points to the UIWebView picking up the .plist locations after it is instantiated (which makes sense if one was to design the class), but before a request is handled. The fix for this would be to apply the patch before the UIWebView is instantiated.
          Hide
          Shazron Abdullah added a comment -

          re-opening based on new evidence.

          Show
          Shazron Abdullah added a comment - re-opening based on new evidence.
          Hide
          Shazron Abdullah added a comment -

          I think the UIWebView/WebKit code is open-sourced, so we can make sure 100% by looking at it.

          Show
          Shazron Abdullah added a comment - I think the UIWebView/WebKit code is open-sourced, so we can make sure 100% by looking at it.
          Hide
          Roy Yang added a comment -

          @shazron Thank you for looking into this so thoroughly, really appreciate it. Please let me know if there is anything else you want me to look at or verify.

          Show
          Roy Yang added a comment - @shazron Thank you for looking into this so thoroughly, really appreciate it. Please let me know if there is anything else you want me to look at or verify.
          Hide
          Shazron Abdullah added a comment - - edited

          Yup, confirmed that the localStorage database path is set during initWithFrame, as expected:
          http://www.opensource.apple.com/source/WebKit/WebKit-7534.53.11/mac/WebView/WebView.mm

          Show
          Shazron Abdullah added a comment - - edited Yup, confirmed that the localStorage database path is set during initWithFrame, as expected: http://www.opensource.apple.com/source/WebKit/WebKit-7534.53.11/mac/WebView/WebView.mm
          Hide
          Angelo Marras added a comment -

          FYI the problem is solved if I apply steps 4-6 described in the Localstorage Plugin (CB-330).

          Show
          Angelo Marras added a comment - FYI the problem is solved if I apply steps 4-6 described in the Localstorage Plugin ( CB-330 ).
          Hide
          Shazron Abdullah added a comment -

          @Angelo - yup that will fix it as well because it absolutely solves the timing issue. I'm slating this for 1.7.0 for the built in solution

          Show
          Shazron Abdullah added a comment - @Angelo - yup that will fix it as well because it absolutely solves the timing issue. I'm slating this for 1.7.0 for the built in solution
          Hide
          Urs Zimmermann added a comment -

          @shazron Really appreciate your work.
          This issue is blocking an update for our app, we see the same issues as described by @roy.
          Do you see any way to avoid this issue using js or the phonegap API with 1.6.1 so we could build on phonegap build?

          Show
          Urs Zimmermann added a comment - @shazron Really appreciate your work. This issue is blocking an update for our app, we see the same issues as described by @roy. Do you see any way to avoid this issue using js or the phonegap API with 1.6.1 so we could build on phonegap build?
          Hide
          Angelo Marras added a comment - - edited

          @Urs - My workaround for Phonegap 1.6.1:

          • In your app's "AppDelegate.m", add the import:
           
          #import <Cordova/CDVLocalStorage.h>
          
          • In your app's "AppDelegate.m", add this to the top of your "application:didFinishLaunchingWithOptions" function:
           
          [CDVLocalStorage __verifyAndFixDatabaseLocations];
          
          • In your app's "AppDelegate.m", replace your "webViewDidStartLoad" function with this:
           
          - (void) webViewDidStartLoad:(UIWebView *)theWebView 
           {
            static CDVLocalStorage* localStorage = nil;
            if (localStorage == nil) {
             localStorage = [[CDVLocalStorage alloc] initWithWebView:theWebView];   
             [localStorage restore:nil withDict:nil];
            }
          
           return [ super webViewDidStartLoad:theWebView ];
          }
          
          Show
          Angelo Marras added a comment - - edited @Urs - My workaround for Phonegap 1.6.1: In your app's "AppDelegate.m", add the import: # import <Cordova/CDVLocalStorage.h> In your app's "AppDelegate.m", add this to the top of your "application:didFinishLaunchingWithOptions" function: [CDVLocalStorage __verifyAndFixDatabaseLocations]; In your app's "AppDelegate.m", replace your "webViewDidStartLoad" function with this: - (void) webViewDidStartLoad:(UIWebView *)theWebView { static CDVLocalStorage* localStorage = nil; if (localStorage == nil) { localStorage = [[CDVLocalStorage alloc] initWithWebView:theWebView]; [localStorage restore:nil withDict:nil]; } return [ super webViewDidStartLoad:theWebView ]; }
          Hide
          Shazron Abdullah added a comment -

          @Urs I'm afraid that for PhoneGap Build there is no way you can patch it currently since all an uploader provides is HTML+JS+CSS assets. 1.7.0 release is slated for next week, and usually it takes a couple of days for Build to catch up. I'm sorry if that doesn't help.

          Show
          Shazron Abdullah added a comment - @Urs I'm afraid that for PhoneGap Build there is no way you can patch it currently since all an uploader provides is HTML+JS+CSS assets. 1.7.0 release is slated for next week, and usually it takes a couple of days for Build to catch up. I'm sorry if that doesn't help.
          Show
          Shazron Abdullah added a comment - Re-fix commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/1fb9c0d9
          Hide
          Samyak Bhuta added a comment -

          @Angelo,
          The below code is throwing exception.

           
          return [ super webViewDidStartLoad:theWebView ];
          

          The exception is as follow ...

          -[AppDelegate webViewDidStartLoad:]: unrecognized selector sent to instance 0x42c280
          *** WebKit discarded an uncaught exception in the webView:didStartProvisionalLoadForFrame: delegate: <NSInvalidArgumentException> -[AppDelegate webViewDidStartLoad:]: unrecognized selector sent to instance 0x42c280
          

          Sure, the exception is ignored and localStorage fix works !

          Show
          Samyak Bhuta added a comment - @Angelo, The below code is throwing exception. return [ super webViewDidStartLoad:theWebView ]; The exception is as follow ... -[AppDelegate webViewDidStartLoad:]: unrecognized selector sent to instance 0x42c280 *** WebKit discarded an uncaught exception in the webView:didStartProvisionalLoadForFrame: delegate: <NSInvalidArgumentException> -[AppDelegate webViewDidStartLoad:]: unrecognized selector sent to instance 0x42c280 Sure, the exception is ignored and localStorage fix works !
          Hide
          alexander.koerschgen added a comment -

          So I just upgraded an app to Cordova-1.7.0 and tried to test data persistence during an iOS upgrade.

          Since I have no iOS 5.0 device at hand, my idea was to launch the application in 5.0 Simulator, do some stuff which will be written to SQL/LocalStorage and then to copy the installed application via Finder to the 5.1 Simulator. Then I would proceed to launch the 5.1 Simulator (by running an empty cordova project from xCode), press the home button and launch the app I just copied.

          Unfortunately, all the data is lost. Indeed, everything stored under Library/WebKit is deleted as soon as the application is launched.

          Thus my question is: what is going to happen, when a user (with the cordova-1.7.0-based app installed) upgrades his iPhone from 5.0 to 5.1? Is the data saved by this fix (and only lost on the simulator) or will it be lost? And is there any way to test this without having to downgrade real devices?

          Show
          alexander.koerschgen added a comment - So I just upgraded an app to Cordova-1.7.0 and tried to test data persistence during an iOS upgrade. Since I have no iOS 5.0 device at hand, my idea was to launch the application in 5.0 Simulator, do some stuff which will be written to SQL/LocalStorage and then to copy the installed application via Finder to the 5.1 Simulator. Then I would proceed to launch the 5.1 Simulator (by running an empty cordova project from xCode), press the home button and launch the app I just copied. Unfortunately, all the data is lost. Indeed, everything stored under Library/WebKit is deleted as soon as the application is launched. Thus my question is: what is going to happen, when a user (with the cordova-1.7.0-based app installed) upgrades his iPhone from 5.0 to 5.1? Is the data saved by this fix (and only lost on the simulator) or will it be lost? And is there any way to test this without having to downgrade real devices?
          Hide
          Shazron Abdullah added a comment -

          @alexander this fix never deletes anything, certainly not the Library/WebKit folder. Did you verify on disk (for the Simulator) that it is actually deleted? If it is actually deleted, it's an Apple thing unfortunately.

          Show
          Shazron Abdullah added a comment - @alexander this fix never deletes anything, certainly not the Library/WebKit folder. Did you verify on disk (for the Simulator) that it is actually deleted? If it is actually deleted, it's an Apple thing unfortunately.
          Hide
          alexander.koerschgen added a comment -

          Yes, I did verify this.

          However, I just went through my testing procedure once again. This time, I pressed the home button in 5.0 Simulator to force a backup. Then I copied the app to 5.1 Simulator again and fired it up. Again, the Library/Webkit was deleted but all data was still there – so I have to assume that the plugin found the Backup and restored the database.

          This gives me confidence, that users having the new version of the app installed will not lose any data when upgrading from 5.0 to 5.1.

          So thanks alot for your efforts!

          Show
          alexander.koerschgen added a comment - Yes, I did verify this. However, I just went through my testing procedure once again. This time, I pressed the home button in 5.0 Simulator to force a backup. Then I copied the app to 5.1 Simulator again and fired it up. Again, the Library/Webkit was deleted but all data was still there – so I have to assume that the plugin found the Backup and restored the database. This gives me confidence, that users having the new version of the app installed will not lose any data when upgrading from 5.0 to 5.1. So thanks alot for your efforts!

            People

            • Assignee:
              Shazron Abdullah
              Reporter:
              Urs Zimmermann
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development