Where does the iPhone Simulator store the installed applications? - iphone

I want to have a look at the app directory from the iPhone Simulator, so that I can see what kind of files it is creating when I use my app and what stuff is in these files (i.e. when it creates the sqlite file for Core Data and stuff like that).

you can find it in
~/Library/Application Support/iPhone Simulator/User/Applications

On Lion the users/[username]/library is hidden.
Use
chflags nohidden /users/[username]/library
in a terminal to display the folder.

Each time you build an application a new directory is created in:
~/Library/Application Support/iPhone Simulator/User/Applications
If you rebuild your application that application directory is renamed. I usually sort the list by most recent and look at the latest directory in there.

Since at least Xcode 6.1, my apps are dumped in
~/Library/Developer/CoreSimulator/Devices/<hexstring>/data/Containers/Bundle/Application/<hexstring>
You can get in your most recently installed app by pasting this into your favorite terminal:
cd ~/Library/Developer/CoreSimulator/Devices/
cd $(ls -t | head -1)
cd data/Containers/Bundle/Application
cd $(ls -t | head -1)

Related

iPhone application, Documents directory on Mac

I'm reading through some of the documentation about File Management on iOS. When you create an application for the simulator, does the application get created somewhere on my hard drive? If so, where is it?
Also, does this have access to the Documents directory? Like if I create some test .txt file, and want to see it in the App->Documents folder, is that possible? Thanks.
Yes. Look here:
~/Library/Application Support/iPhone Simulator/4.3.2/Applications
Change the 4.3.2 to be the version of the Simulator you are using.
Within that folder you will find your apps, except the they are named cryptically. Open one of those folders and you will find your app, named as you recognize it, and the Documents, Library and tmp folders. Documents is where you find the docs that your app creates and uses. You can, in fact, makes changes to the files in the Documents folder or just access their content to see what your app sees or writes.
Under XCode 6, the document directory for your app is quite hidden:
~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//
You can find the directory for your app with this command:
$ sudo find ~/Library/Developer/CoreSimulator/Devices -name <APP_NAME>.app | grep -o '.*/'

iPhone simulator folder not in Application Support

I am creating an application that write some data to the database. For checking I need to open the database in applications.
I think it should be in
~/Library/Application Support/iphone simulator....
I have not found the iphone simulator folder in Application Support.I have installed ios 4.2, and simulator is working properly.
Where can I find it?
Xcode versions 3.x-5.x
Simulator usually is installed together with SDK so most probably you should look (e.g., if you installed Xcode 3.1 and SDK 4.3 in their default locations) within:
/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iOS Simulator.app
Apps that are installed on your iPhone Simulator should be (if for example compiled for iOS 4.3) located in:
~/Library/Application Support/iPhone Simulator/4.3/Applications/[app GUID]
If you are looking for .sqlite database within Application, it should reside in:
~/Library/Application Support/iPhone Simulator/4.3/Applications/[app GUID]/Documents/[appname].sqlite
Xcode 6
The simulator devices are located in:
~/Library/Developer/CoreSimulator/Devices/
so your application data (e.g. application database in app Document folder) will be in
~/Library/Developer/CoreSimulator/Devices/[simulator device id]/data/Applications/[app GUID]/Documents/[appname.sqlite]
On Mac OS X 10.7 the users/[username]/Library is hidden. Reveal it using:
chflags nohidden ~/Library
In IOS5, follow this step
Right Click finder in Dock.
Click 'Go to Folder'.
Give folder name as "/Users/'USER NAME'/Library/Application Support/iPhone Simulator/"
It will take you there.
NOTE: When you run the simulator, it creates a directory under your home directory located at:
~/Library/Application Support/iPhone Simulator/
When you install an application onto the simulator, it creates a sandbox for the application in a path that looks something like this:
~/Library/Application Support/iPhone Simulator/user/Applications/<GUID>
Where <GUID> is a directory with the name being a GUID assigned to the application during the installation process. The GUID isn’t particularly necessary to find for you application, and the path to your application’s sandbox can be found with a quick display of command-line foo. From the ~/Library/Application Support, run:
Deminem$ find ./ -name "AppName.app"
And, voila. It will return a list of all the sandbox directories which contains this application. The "private" data for your app inside the directory:
~/Library/Application Support/iPhone Simulator/user/Applications/<GUID>/Documents
Good luck! ;)
Now on ios 8 the application data is located at Library/Developer/CoreSimulator/Devices/DEVICE NUMBER/data/Containers/Data/Application/APPLICATION ID
On XCode 8. the sqlite file is in
~/Library/Developer/CoreSimulator/Devices/[DEVICE ID ]/data/Containers/Data/Application/B4813EE5-CC8E-4728-872E-41918AD1C14D/Documents/[APPLICATION NAME].sqlite
I don't know the mean by "B4813EE5-CC8E-4728-872E-41918AD1C14D".
The way to get DEVICE ID:
Click to dropdown the simulators list
Click "Add Additional Simulators..."
Select the simulator you are using
We are now up to simulator 5.0 and iOS 6 is in beta 4 stage. All previous answers and comments are out of date.
I would suggest testing with
ls -la ~/Library/Application\ Support/iPhone\ Simulator/*.*/Applications
To answer the specific question about databases
find ~/Library/Application\ Support/iPhone\ Simulator/*.*/Applications -name \*.sqlite
That should last until Apple makes a drastic change.
It sounds like you're talking about the SQLite file used by Core Data – if so, that file should be in ~Library/Application Support/iPhone Simulator/4.2/Applications/[AppID]/Library/ (assuming you're simulating iOS 4.2). If it's not there, I'm not sure where else it would be.
You can find it here
/Users/YOURUSER/Library/Application Support/iPhone Simulator/5.1/Applications
or
/Users/YOURUSER/Library/Application Support/iPhone Simulator/6.0/Applications
You can also write two lines of code that will tell you exactly where your app is located.
NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
NSLog(#"%#", appFolderPath);
In iOS 10, Xcode 8.3.3,
Find the Document path from
NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
then you can find the sqlite file in path printed

Compile directly to /Applications from Xcode

First off, I am not publishing this app to the app store and this is a jailbroken phone.
Anyone know how to compile apps directly to the /Applications folder with Xcode? Currently, I am having to compile to the /var/mobile/Applications folder and copying it to the /Applications folder on the device. It would be very convenient if the app could be compiled directly to the /Applications folder. Google doesn't seem to have any results on this topic.
Thanks in advance...
I don't have a jailbroken iPhone, so I can't say if this works, but presuming you can mount the iPhone as a volume on the Mac, you can add a custom script to the compilation in Xcode that does the copying for you.
Presuming that your iPhone is mounted in /mnt/My iPhone
You would add a custom build phase (Editor > Add Build Phase > Add Run Script Phase) and the script would do something like:
cd /var/mobile/Applications
cp myappfile "/mnt/My iPhone/Applications/"
If XCode compiles applications into the same target directory every time, could you put in a symlink to point to your mounted phone? The OS X docs are in the ln(1) manpage, look for -s for details on symlinks.
e.g., remove /var/mobile/Applications/, and replace it with a symlink to wherever your phone's /Applications/ directory is, (I'm guessing /Volumes/WakePhone/Applications/):
rmdir /var/mobile/Applications
ln -s /Volumes/WakePhone/Applications/ /var/mobile/Applications
Of course, this will only let you compile when your phone is mounted. This might be too much hassle.
Why is copying over your application so onerous that you want to compile directly onto the device? There is probably a better solution than this. :)

How can I install a .ipa file to my iPhone simulator

I have an iphone simulator running on my Mac.
I have a .ipa file, can you please tell me how can I install it on the simulator?
You can't. If it was downloaded via the iTunes store it was built for a different processor and won't work in the simulator.
I found an .ipa file that I wanted using iTunes and copied it over to my desktop.
After that I changed the extension to .zip and extracted it.
Next I found the Payload folder and moved the application inside to my desktop.
Finally I moved that application to my iPhone simulators applications folder found at:
HD
> Applications
> Xcode.app (right click - Show Package Contents)
> Contents
> Developer
> Platforms
> iPhoneSimulator.platform
> SDKs
> iPhoneSimulator6.0.sdk
> Applications
(Note: Some apps crash more often than others.)
In Xcode 6+ and iOS8+ you can do the simple steps below
Paste .app file on desktop.
Open terminal and paste the commands below:
cd desktop
xcrun simctl install booted xyz.app
Open iPhone simulator and click on app and use
For versions below iOS 8, do the following simple steps.
Note: You'll want to make sure that your app is built for all architectures, the Simulator is x386 in the Build Settings and Build Active Architecture Only set to No.
Path: Library->Application Support->iPhone Simulator->7.1 (or another version if you need it)->Applications
Create a new folder with the name of the app
Go inside the folder and place the .app file here.
Update for Xcode 9.4.1+
Hope my answer is getting seen down here as this took me a while to figure out but I just got it working.
First of all you need to build and run the App on your simulator. Then you open the Activity Monitor. Double click the name of your App to find its content.
In the next screen open the Open Files and Ports tab and find the line with MyAppName.app/MyAppName.
Copy the link but make sure to stop at the MyAppName.app. Do not copy the path following it.
Control click onto the finder icon and select Go to folder.
]
Paste the path and click enter. You will see your MyAppName.app file.
Copy it to the Desktop and zip it. Move it to your desired 2nd computer and unzip the file. Build a random project to have a simulator open.
Lastly: Literally drag and drop the App from your Desktop into your Simulator. You will see the install and the App opens and does not crash.
You cannot run an ipa file in the simulator because the ipa file is compiled for a phone's ARM architecture, not the simulator's x86 architecture.
However, you can extract an app installed in a local simulator, send it to someone else, and have them copy it to the simulator on their machine.
In terminal, type:
open ~/Library/Application\ Support/iPhone\ Simulator/*/Applications
This will open all the applications folders of all the simulators you have installed. Each of the applications will be in a folder with a random hexadecimal name. You can work out which is your application by looking inside each of them. Once you have found out which one you want, right click it and choose "Compress ..." and it will make a zip file that you can easily copy to another computer and unzip to a similar location.
UPDATE: For Xcode 8.0+ you need to follow below Steps:
Download application from iTunes
Select downloaded app, right click show in finder
Copy .ipa file to Desktop, rename it to .zip file
Extract that .zip file and you will get directory with application name
Check that directory you will find app file in Payload folder, copy this app file
Go to ~/Library/Developer/CoreSimulator/Devices
FYI: Library folder is hidden by default in mac, you can see hidden file using below command.
defaults write com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app
Now here you'll see many directories with long hexadecimal names, these all are simulators.
To find your desired simulator, sort these directories using "Arranged By > Date Modified".
Select that simulator file and go to below location.
<HEXADECIMAL-SIMULATOR-STRING>/data/Containers/Bundle/Application/
Create new folder name with <download-app-name> and paste app file in that folder
Open Terminal and run below command to install this application
xcrun simctl install booted <APP_FILE_PATH>
Example <APP_FILE_PATH> will be looks like below:
~/Library/Developer/CoreSimulator/Devices/<HEXADECIMAL-SIMULATOR-STRING>/data/Containers/Bundle/Application/<APP_NAME>
First of all, IPAs usually only have ARM slices because the App Store does not currently accept Simulator slices in uploads.
Secondly, as of Xcode 8.3 you can drag & drop a .app bundle into the Simulator window and it will be installed. You can find the app in your build products directory ~/Library/Developer/Xcode/DerivedData/projectname-xyzzyabcdefg/Build/Products/Debug-iphonesimulator if you want to save it or distribute it to other people.
To install from the command line use xcrun simctl install <device> <path>.
device can be the device UUID, its name, or booted which means the currently booted device.
For Xcode 10, here's an easy way that worked for me for a debug IPA (development profiles)
Unzip the IPA to get the Payload folder.
Within the Payload folder is the app executable.
Drag and drop the app to an open simulator. (You might see a green add button when you drag it over the simulator)
It should install that app on that simulator.
You can run the application file of project in simulator - not .ipa file.
You can get it from:
Libraries-->Applicationsupport-->iphone simulator-->4.3(its ur simulator version)-->applications-->then u can see many files like 0CD04F.... find out your application file through open it.
You can copy the file to your system(which system simulator u need run ) location Libraries-->Applicationsupport-->iphone simulator-->4.3(its your simulator version)-->applications-->
Then open the simulator 4.3 (its your simulator version where you pasted). You can see the application installed there.
Getting from other people:
Please tell them to find out Libraries-->Applicationsupport-->iphone simulator-->4.3(its ur simulator version)-->applications-->then you can see many files like 0CD04F.... from their system and receive that file from them.
After they have got the file, please copy and paste the file in to your system `Libraries-->Applicationsupport-->iphone simulator-->4.3(its your simulator version)-->applications-->(paste the file here).
Then you can see the app is installed in your system simulator and you can run it after clicking the file.
Copy From Here:
- Run the application in the Xcode.
- Select Finder go to Go and click on select Library Library/Application Support/iPhone Simulator/7.0.3-64/Applications
- Select 32 bit folder Copy your application.
Paste To Here:
- /Applications/Xcode-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhone Simulator. SDK/Applications
- Paste here and run the simulator.
With Xcode 6:
It's very possible to build and install on a simulator.
I did it by copying the debug build configuration (I called it SimRelease for my example below) in the project settings. I changed the architectures to i386 and x86_64 (not sure how necessary this was), but key difference to change between the copied build configuration is build for active architecture set to NO. After that a couple simple command line tools will do the rest!
xcodebuild -scheme YOUR_SCHEME -configuration SimRelease -sdk iphonesimulator8.1
Depending on where you have your DerivedData set you need to go find the outputted .app folder. Once you've found it you can simply install it on any simulator device. To find the device UUID's open Xcode and go to Window->Devices you'll see the list of the device instances and you can grab the UUID's. For a trivial script you could grab all of them from: ~/Library/Developer/CoreSimulator/Devices/ and install on every device.
From there the simple command to install on a device is:
xcrun simctl install DEVICE_ID APP_FOLDER_LOCATION
Here's a simple shell script to take the app and install it on every device:
app_dir=$1
current_dir=$(pwd)
cd ~/Library/Developer/CoreSimulator/Devices/
devices=$(ls -d */)
cd "$current_dir"
for device in $devices
do
device_id=${device%/}
xcrun simctl install "$device_id" "$app_dir"
done
Hope this helps! Took me a while to figure out the best way to do it.
Step to run in different simulator without any code repo :-
First create a .app by building your project(under project folder in Xcode) and paste it in a appropriate location (See pic for more clarity)
Download Xcode
Create a demo project and Start simulator in which you want to run the app.
Copy the .app file in particular location(ex :- Desktop).
cd Desktop and Run the command (xcrun simctl install booted appName.app),
App will be installed in the particular booted simulator.
Tested on iPod touch (7th generation) Simulator 13 (iOS 15.0)
Xcode and Xcode Command Line tools are already installed
Since we have an .ipa file, we can get the .app file from it
Rename .ipa file as .zip and extract the contents
Once the zip file is extracted, we can find the Payload folder which contains App_Name.app file
Open Terminal or iTerm2 app
Navigate to the folder which contains .app file
To list all iOS connected devices & iPhone simulators -> Also shows the UDID of all devices
xcrun xctrace list devices
Boot the simulator
xcrun simctl boot <UDID>
Launch the simulator
open -a simulator
Install the .app file
xcrun simctl install booted <App_Name>.app
Just drag and drop .app file to simulator it will install app automatically.
I have checked in iPhone simulator 13(iOS 15.4)

Cleaning up the iPhone simulator

Is there a straightforward way to clean up the directory where xcode deploys an app when building for the iPhone simulator? I have a sqlite database that gets copied into the Documents folder on startup if necessary. The problem is that I might change my schema, but the new database won't get copied, because one already exists.
Ideally, every time I build, it would nuke the previous contents. Is this possible, or do I have to manually do it?
From Apples Dev Resources:
To set the user content and settings of the simulator to their factory state and remove the applications you have installed, choose
Device > Erase All Content and Settings.
(On older versions: iPhone Simulator > Reset Content and Settings.)
The simulator installs apps into:
"$HOME/Library/Application Support/iPhone Simulator/User/Applications"
Also check:
"$HOME/Library/Developer/CoreSimulator/Devices"
The GUID files and directories match up to the simulator's installed apps.
Manually delete all those files/directories to remove all applications from the simulator.
I know there is some way to add scripts to the build process in XCode.
Also it looks as if XCode changes the GUID it uses each build (the directory where my app sits changes between builds in XCode), so trying to delete the same directory all the time won't work. If you are only working on one app at a time then clearing out the entire directory would be an option.
The way I do this is to simply click and hold on the icon for my app in the simulator--then when it starts to wiggle click the black and white (x). A message will pop up asking whether you really want to delete and you just click yes. The next time you build and deploy your app it will use the new sqlite db without a hitch and you don't have to go muck around in the filesystem.
After iOS 5 on Mac OS X Lion, you can try:
Create a script called RemoveSimulatorApps.command that contains:
rm -rf "$HOME/Library/Application Support/iPhone Simulator/5.0/Applications/*"
Save this script to a directory in your PATH.
Make the file executable, such as:
chmod +x RemoveSimulatorApps.command
Assumptions
You may want to invoke this from a keyboard favorites buttons, such as on a Logitech or Microsoft keyboard with programmable keys (hence, saving it as a .command file instead of say, .sh)
You are okay with blowing away everything in the iOS simulator (ideal if you're just actively working on one app)
All the notes from others apply about being a good upgradable app etc. (I personally found this useful nonetheless b/c I have development mode switches that reload a database in a specific state I was trying to do some consistent robustness/error handling on)
it may be overkill but..
you can also use the menu and 'Reset Content and Settings...'
What you are really trying to do is to clear out your database, if you've changed the schema. One way to do this, and it would make you happier in the long run when you start shipping version 2.0, 3.0, etc. of your app, is to check the version of your sqlite table, and if it has changed, then discard the old file and use the one in your bundle.
Finding a way to clean up the Simulator won't help the real world problem of how to clean up a customer's iPhone when you ship a new version with a new schema.
For extra points, after determining that you have encountered an old schema, you may want to copy the new database over without destroying the old one, and load any interesting data out of the old database, into the new one. Then blow away the old database. That way you can preserve your user's additions to the database.
for Xcode >= 6
xcrun simctl list | grep -oh '[A-Z0-9]\{8\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{12\}' | xargs -n1 xcrun simctl erase
If you are using Xcode 9 -> Menubar -> Hardware -> Erase All Content and Settings
As of Xcode 6, you can do this from the command line with:
xcrun simctl erase
Also, the iOS Simulator app (both the Xcode 6 version and older versions) has a menu item called "Reset Content and Settings" that can be used to erase the currently booted device.
This works with Xcode 6:
xcrun simctl list | grep -oh '[A-Z0-9]\{8\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{12\}' | xargs -I{} xcrun simctl erase {}
For .bash_profile
alias cleansim="xcrun simctl list | grep -oh '[A-Z0-9]\{8\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{4\}-[A-Z0-9]\{12\}' | xargs -I{} xcrun simctl erase {}"
As of Xcode 6:
xcrun simctl erase <sim udid> <- resets the simulator.
The following command in the terminal will wipe all of your simulators as if you had just installed them.
$xcrun simctl erase all
Just close simulators before you run it.
Clear Xcode Cache;
Command+Option+Shift+K
Command+Shift+K
(Use both of them because they have different functionality)
Clear Derived Data content ;
Menu Bar -> Window -> Organizer -> Projects -> Select Your Project
Right Pane shows the name of folder and also delete button at the right side allows you to delete all derived data contents.
Clear Simulator Cache;
Menu Bar -> iOS Simulator -> Reset Contents And Settings
As I was explaining in a comment under the validated answer:
I was testing adding and removing calendar subscriptions. On a real device, you can remove a calendar subscription in Settings, Accounts but this menu does not exist in iOS Simulator and I did not want to reset the whole simulator.
So I ended up locally versioning my Device folder with git and perform the following commands to remove a calendar subscription after I added it:
$ git reset HEAD --hard
$ git clean -f
So the steps are:
Install your application on the iOS Simulator and do what you have to do
Identify your device in ~/Library/Developer/CoreSimulator/Devices/ and do a cd to it, then git init to create a git repository
Once you want to save the state, perform git commit -a "Message"
Do whatever changes the settings (ex: adding a calendar subscription) and perform your tests
Shutdown the simulator
Do git reset --hard HEAD
Start the simulator, all changes done after git commit are gone.
In XCode, go to the Window menu option, select Devices and then you can just delete the ones you no longer need.
For Xcode <= 5
I added the following to my ~/.bash_profile
alias cleansim='rm -r ~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/*'
It just nukes all of the apps on the sim.
Using Xcode 14.1 and an iphone14 simulator I deleted the app as I would on an iPhone. This deletes all data from the app. When I rebuilt, and all the data in the Documents folder was removed.
Answer for Xcode 14 in Mac OS Ventura 13
Open your simulator. You can do in your terminal: open -a simulator
Then just Device -> Erase All Content and Settings...