Use Case
If WiFi fails, your ajax call fails and your backup re-submit code fails, you may need a last ditch solution of physically grabbing your form data from inside your PhoneGap app, off of an individual iOS device.
Prerequisites
Make sure the app is coded to save data locally using HTML5 localStorage API.
Once the localStorage functionality is tested and working, and you have your PhoneGamp / cordova app running on an iPad, you can use PhoneView to access the file system on your the iPad.
Install DB Browser for SQLite on your Mac. Under the hood, cordova saves your localStorage data as a simple SQLite database.
Retrieve the Data
- Connect your device to your Mac and open PhoneView Demo
- Go to Apps in the main nav on the left.
- Click on Settings in the top nav icons bar and you’ll see this dialog window:
- Check the “Show Entire Disk in Disk Mode” and “Show All Apps in Apps Mode (Developers Only)” boxes. You’ll get a warning confirmation popup, which you should accept by clicking OK.
- You’ll now see your custom cordova app listed under Apps:
- The folders you want is yourApp/Library/Caches/ and yourApp/Documents/Backups/. The file should be called something like “file__0.localstorage” in /Library/Caches or “localstorage.appdata.db” in /Documents/Backups. It’s essentially a SQLite file, and can be opened using an app that lets you view SQLite files.
- To open it, you need to first copy the Library folder to your Mac.
- Click the Library folder to to select it
- Click on Copy from iPhone button in the top icons navbar
- Choose a location to save it on your machine.
- Launch DB Browser for SQLite
- Open your recently copied “file__0.localstorage” or “localstorage.appdata.db” files from your Mac in DB Browser for SQLite
- Click on the Browse Data tab towards the top of the interface
- You should see your localStorage Key / Value pairs listed as a SQL table:
- If you stored your Values as Arrays, your actual data may be stored as a BLOB data type and not plain text
- Select your BLOB value in the table and look at the right side of the interface, under Edit Database Cell
- Make sure the Mode is set to “Binary”
- You should be able to see your data with very bad kerning
- Click the “Export” button above the cell content area
- Save your file as .txt and open the .txt in any text editor, like SublimeText, to access your data as plain text.