location of database created by the application - iphone

I have opened a database using sqlite3 in my application. When i run the application in the simulator, this database might be created and i'm playing with it. But now i need to know the location (to be accessed from ma mac) where this database is created. Surely it is not in the application folder as i'm not seeing it. I doubt it to be somewhere in the location where the simulator is installed. Anyone knowing the location. pls help me finding it.

If you're looking for the actual file on your Mac, try looking in this folder:
/Users/YOURUSERNAME/Library/Application Support/iPhone Simulator/User/Applications/
There should be a bunch of folders with long names. If you've recently built your app for the Simulator, order the folder by Date and the newest will be at the top. The folder contains a Documents folder, but you can also right-click on the app to "Show Package Contents", which might contain your database.sqlite file.

Related

In Xcode 4.1 Database file is not displaying in build file

Using xcode 4.1 I am developing an application which is having database integration. I am able to do all functions on firefox Sqlite Manager plugin. When I add data to firefox, the data is being added properly by query. But I am not able to find the database file in the build folder of my application.
How can I get this file from within the application and from where ?
I have to check that the data inserted from the application is properly inserted or not because at the time of selecting & displaying the data, the application crashes.
Thanks in advance for guiding me & solving this problem.
Run application in iphone simolator and then insert data and the see the sqlite file at the path
home>Library>Application Support>Iphone Simulator>simulator type(like 5.0)>Applications
this path have many folders. folders have application data of all installed applications in simulator. search for your application and the open
Documents folder
here you have your sqlite file which store all your inserted data
Sometimes folders are hidden. so please check for hidden files and folders
Hope this will help.

Is there a shortcut to open the directory where Xcode installs apps on the simulator?

I thought I came across a menu item or a right-click command akin to "Open app bundle location in Finder" but I can't find it. Maybe it was a secret wish in during dream. Maybe not. Does this exist?
EDIT: I know where these files live in the file system. I've added the iPhone Simulator folder to the dock in order to make it easy to get there. I'm doing a lot of work where I have to verify that the app bundle got updated as necessary. As I said, I thought I had seen a right-click menu that could get you there faster.
Well, I'm not sure if there is such a shortcut, but you definitely can browser through your files by going to :
~/Library/Application Support/iPhone Simulator/
Try SimPholders 1.5. From their website:
A small utility for fast access to your iPhone Simulator apps. Opens
folder in Finder, resets library and documents, and deletes the
selected app.

iphone - how do I create a bundle and put files on it at run time

My app generates 3 files every time the user saves a project. I would like to be able to build a bundle at run time, and save all files to that bundle and save it to the app's directory. So if the user wants to move the project to the desktop its just the matter of dragging one bundle (= a directory that looks like a file, like the Mac OS X apps and Pages files)...
I googled around and found nothing.
How do I do that at run time?
thanks.
Bundles are really just folder hierarchies conforming to a specific structure – see the Bundle Programming Guide. You can use NSFileManager to create the folders in question, NSPropertyListSerialization to create the Info.plist, etc.

How do i test my app data persistence during development?

My question is related to the following three questions.
iPhone What happens to previous data when app is upgraded to new version
How the application upgrade works in iPhone
Preventing erasure of user data while upgrading iOS application via iTunes
Here are my 2 questions.
Am I supposed to create a "Documents" directory manually on filesystem or create just a "group" in xcode, so that when app is upgraded, data stay persistant?
How I can test the app persistance during the app development on simulator or on IPhone?
Thanks.
Neither. The Documents directory is created for you when your app is installed. You can get the path to it using:
NSString *docuDir = nil;
NSArray *list = NSSearchPathForDirectoriesInDomains(
NSDocumentsDirectory, NSUserDomainMask, YES/*expand tilde*/);
if ([list count]) docuDir = [list objectAtIndex:0U];
As #Ben said, the directory is only deleted when you explicitly uninstall the app (delete it from within Springboard). When you build and run, Xcode effectively does an in-place upgrade of your app. If everything is intact then (and there's no reason it wouldn't be), you should be fine.
When the app is upgraded your Documents folder is left intact. You can copy files into the Documents directory the first time your app is run such as a sqlite file for example, obviously only if it doesn't already exist. If you use CoreData then it will automatically store your data there. You will need to be able to run migration scripts if your data schema changes on upgrade, so keep that in mind. CoreData has migration features to take care of this for you and of course you can do it manually too.
When you run an app in the simulator it also leaves the Documents directory intact, so you have to delete the app from the simulator to simulate a fresh install. An upgrade is simulated simply by running your code since the Documents folder was created on the 'fresh install' first run.
Another way to approach this would be look at the Documents folder. If you are running your app in the simulator, then your app's Documents folder will have a path something like this:
/Users/itsaboutcode/Library/Application Support/iPhone Simulator/4.1/Applications/SOME_LONG_HEX_KEY_THAT_MAPS_TO_YOUR_APP/
If you are testing on an iDevice, then use Xcode's Organizer window's Summary tab. At the bottom there's a section called Applications. You app will be near the top of that list and it will have a toggle triangle - which you will click on. This will reveal "Application Data" which can be downloaded by clicking on downward pointing arrow to the right.
The iPhone Simulator has the advantage that the Documents folder and its contents can be modified at will. The Application Data on iDevice is read-only (except, of course, for your app at runtime).

Where is the sqlite3 database stored on the iphone emulator?

Now that I have a read-only application working, I am working on the insert statement. The insert returned OK in my code, but the read-back (in the code) came up empty, so I want to use the command line or browser to read. Can I copy the DB off the emulator and into my laptop for access with other utilities?
You can access the documents directory of your app at ~/Library/Application Support/iPhone Simulator/<SDK VERSION>/Applications/<SOME RANDOM HASH>/Documents
Note that the SDK version will be different depending on what you are building under, and the hash is tough to figure out which one is yours. Just inspect the folders and look for a YOURAPP.app binary to figure it out.
What database?
Assuming you have created it in your app's documents folder, app sandboxes for the simulator are in ~/Library/Application Support/iPhone Simulator/<version>/<uuid>, and contain the application and it's Documents, Library and tmp directories.