Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open database sqlite file on iPhone real device?

I'm debbuging a app in my real device by cable. I've a iPhone 6. I want check my database and operate with sqlite3 to query my results. The other questions and tutorials explain to do this only in simulator but I'm using a real iPhone.

In AppDelegate, I prints the path of database:

print(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! as String) /Users/myname/Library/Developer/CoreSimulator/Devices/DAE93E57-7004-45F6-9B93-E79CA1AEEEFA/data/Containers/Data/Application/D7A4F27E-6F11-4941-A1B0-0337ABF788AB/Documents

So, I take the path and access from terminal and access my database with sqlite3 DatabaseFile

But when I debugging in my device, the path that's printed not works. I tried use the printed path cd /var/mobile/Containers/Data/Application/3257D423-C198-41A5-B29D-B31E99F84F34/Documents /usr/bin/CD: line 4: cd: /var/mobile/Containers/Data/Application/3257D423-C198-41A5-B29D-B31E99F84F34/Documents: No such file or directory

This error happens because this is of iOS system, I think.

like image 820
Augusto Avatar asked Jun 13 '18 01:06

Augusto


2 Answers

Xcode 10.1

In Xcode, go to Window > Devices and Simulators

enter image description here

In the Devices tab, select your application, then click on the Gear icon, then click Download Container... enter image description here

Choose the location you want to save the file, then click on Save.

Go to Finder and find the .xcappdata file you just downloaded, then right click and select Show Package in Contents

enter image description here

The contents folder will open. Your .sql file is in AppData > Library > Application Support

enter image description here

I recommend downloading DB Browser for SQL File, and opening the .sql file with that. It works wonders!

like image 62
Cherick04 Avatar answered Sep 21 '22 15:09

Cherick04


In recent versions of Xcode (8 and up, I think), open this with Window menu --> Devices. Find the device in the device list and look at the installed apps list for the device. Each app that you've built and installed on the device will be listed (and maybe some others). Select your app and click the gear menu below the list. Clicking the "Download" item on the pop-up menu will enable you to copy the app's documents, library, and other directories to your Mac.

NB: This will download an .xcappdata file. Right-clicking on that and selecting "Show Package Contents" will allow you to drill down to the actual sqlite file.

like image 24
Praveen Gowlikar Avatar answered Sep 22 '22 15:09

Praveen Gowlikar