How to run iPhone emulator WITHOUT starting Xcode? - xcode

On my old Mac running Snow Leopard, I could type "ios" into spotlight and it would start up the iPhone/iPad emulator by itself.
I have since had to get a new machine running Lion. I have installed Xcode for Lion, I have installed the developer tool options from the preferences panel.
But the "ios" option is no longer there :( The only way now seems to be to run Xcode, create an empty project and then launch emulator with the run option.
I have searched and searched the intertubes and the facewebs, but nothing helps.
Does anyone know how to run only the emulator on Lion?
UPDATE:
THIS IS RESPONSE TO #ike_love thread below.
THAT answer is not assured to work on all Yosemite machines.

Assuming you have Xcode installed in /Applications, then you can do this from the command line to start the iPhone Simulator:
$ open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
(Xcode 6+):
$ open /Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app
You could create a symbolic-link from your Desktop to make this easier:
$ ln -s /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app ~/Desktop
(Xcode 6+):
$ ln -s /Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app ~/Desktop
As pointed out by #JackHahoney, you could also add an alias to your ~/.bash_profile:
$ alias simulator='open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/De‌​veloper/Applications/iPhone\ Simulator.app'
(Xcode 6+):
$ alias simulator='open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app'
(Xcode 7+):
$ alias simulator='open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app'
Which would mean you could start the iPhone Simulator from the command line with one easy-to-remember word:
$ simulator

The easiest way without fiddling with command line:
launch Xcode once.
run ios simulator
drag the ios simulator icon to dock it.
Next time you want to use it, just click on the ios simulator icon in the dock.

In XCode 7+ the location is now
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
Run it from the command line
$ open -a Simulator

From Terminal you have to run:
open -a Simulator

No need to do anything on the commandline.
Just use spotlight to run simulator.app

is it helpful to you see the image
Edit
Now with new Xcode if the icon of the Xcode is on dock you can just right click it and form the menu you can select Open Developer Tool and in the sub menu you can select the iOS Simulator to open the simulator without opening the Xcode.!

You can get it to launch via spotlight if you create an Automator launcher for it:
Open Automator.app
Choose type of Application
Select Actions > Library > Utilities > Launch Application
Open the dropdown of applications that can be launched and choose Other
You can't directly select the Simulator app because it's inside the Xcode.app package. So instead you'll have to navigate to it in a separate Finder window and drag it onto the file selector window. It will be at one of the following paths depending on your version of Xcode (oldest to newest):
/Applications/Xcode.app/Contents/Developer/iOS Simulator.app
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iOS Simulator.app
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
Finally, save this Automator app in your applications folder as iOS Simulator.app
To get a nice icon for the Automator app you just made, you can do the following:
Right click iOS Simulator.app and choose Get Info
Click the icon in the upper left corner and do Cmd-C to copy it
Right click your Automator app and choose Get Info
Click the icon in the upper left corner and do Cmd-V to paste

As the multitude of answers indicate, there are lots of different ways to address this issue. Not all of them address what is my number one issue, and what seems to be the asker's priority, as well: The ability to launch from Spotlight.
Here's the solution that works well for me, and should work with any OS X and XCode versions. I've tested it on OS X 10.11 and XCode 7.3.
Initial setup does require launching XCode, but after that, you won't need to just to get to the Simulator.
Setup
Launch XCode
From the XCode menu, select Open Developer Tool > Simulator
In the dock, control (or right) click on the Simulator icon
Select Options > Show in Finder
While holding down Command and Option, drag the Simulator icon to the applications directory. This creates an alias to it.
If desired, rename the alias from "Simulator" to "iOS Simulator". Whatever you name it is what it will show up as in Spotlight.
Note: There are other ways to get to the location of the Simulator app (steps 1-4), such as using Go to Folder… in the Finder, but those require knowing the location of the Simulator to begin with. Since that has changed from version to version of XCode, this way should work regardless of these changes.
Use
Launch Spotlight (command-space, etc.)
Type "simulator" or "ios" (if you renamed the alias).
If necessary, use the down arrow to scroll to the Simulator alias. Eventually, spotlight should learn and make the alias the top choice so you can skip this step.
Hit return

Try below instruction for launching iphone simulator:
Goto Application Folder-->Xcode app-->right click to Show Package Contents-->now show files in xcode contents-->Developer-->Platforms-->iPhoneSimulator.platform-->Developer-->Applications--> now show iOS Simulator app click to launch iphone simulator...!

With Xcode 6 the location of the simulator has changed to:
/Applications/Xcode.app/Contents/Developer/Applications/iOS Simulator.app
It can no longer be found here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app
I hope this helps someone since I sometimes want to start the simulator from terminal.

The solutions above didn't work for me in ZSH. I needed to escape the dot in the iPhoneSimulator.platform. This works for me:
alias simulator="open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app"
This could be even more resilient version:
alias simulator="open -a 'iOS Simulator'"

There's a far easier way:
Hit command + space, Spotlight Search will appear
Type in iOS Simulator and hit return
Done.
----- In follow up to #E. Maggini downvote---
Yes you can still easily access iOS Simulator using Spotlight.

In the terminal:
For Xcode 9.x and above
$ open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
For Xcode-beta 9.x and above
$ open /Applications/Xcode-beta.app/Contents/Developer/Applications/Simulator.app

I know it is an old question, but this might help someone using Xcode11+ and macOS Catalina.
To see a list of available simulators via terminal, type:
$ xcrun simctl list
This will return a list of devices e.g., iPhone 11 Pro Max (6A7BEA2F-95E4-4A34-98C1-01C9906DCBDE) (Shutdown). The long string of characters is the device UUID.
To start the device via terminal, simply type:
$ xcrun simctl boot 6A7BEA2F-95E4-4A34-98C1-01C9906DCBDE
To shut it down, type:
$ xcrun simctl shutdown 6A7BEA2F-95E4-4A34-98C1-01C9906DCBDE
Alternatively, to launch a simulator:
open -a simulator
Source : How to Launch iOS Simulator and Android Emulator on Mac

The easiest way is to use Spotlight Search. Just click CMD+Space and type in search Simulator. Just like this:
And in few seconds emulated device will be loaded:
To switch to another device you can use menu under Hardware -> Device
There are few different cool instruments you can use under Hardware menu, such as orientation change, gestures, buttons, FaceID, keyboard or audio inputs.

Go into Finder.
On the sidebar, click applications.
Find Xcode in Applications.
Right click Xcode by whatever settings you have (usually two finger click [not tap]).
Click "Show Package Contents."
Go into the Contents folder.
Search simulator.
Wait 30 secs for it to load.
Scroll down and find iOS Simulator.
You may drag this onto the dock for easier access.
I hope this helps!

In case you were trying to open multiple distinct simulators at once:
Open the Simulator app, not Xcode.
Then File >> Open Device >> Select iOS version >> select device.
The location of the 'open device' has changed in different Xcode versions so it may be at a different place

I created an automator app based on #trojanfoe's answer so you can launch iOS Simulator directly from your Dock https://github.com/tsdexter/ios-simulator-expo-utilities/

From Terminal just run this command:
ios-sim start
Or,add this to your ~/.profile to save yourself a few keystrokes:
alias ios="ios-sim start"
Not sure which version of Max OS X and Xcode this command became available. I'm running 10.10.3 and 6.3 respectively.

Related

Xcode: iOS Simulator Dev Menu will not open

Specs: React Native, xCode, iOS Simulator
I'm currently running xCode and just trying to start my hello world however despite numerous approaches I cannot get the dev menu in the iOS Simulator to open. The hotkey CMD + D will not work.
I have tried:
I checked and unchecked the simulator keyboard settings, “Connect
Hardware Keyboard”. Reference
I have tried “Reset Content and Settings” in the simulator menu.
Switching between scheme settings for the project. “Check your
scheme settings. The current scheme shows at the top of Xcode. Click
on it, then Edit Scheme. Under "Run", make sure the build
configuration is set to Debug. If it's set to something different,
you won't get the dev menu.” Reference
Restarting the simulator and restarting my mac.
Let's you try command + control + z
I also faced the same issue and after searching a lot I finally got a solution.
Create a fresh project by react-native init and see if it(dev menu) works or not? If it does, just upgrade the react-native version of your project. In my case, creating a fresh project worked.
I faced a similar issue when the default launch device as iPhone 11. But when I ran the command to run with iPhone 11 Pro developer menu came back. May be specific to a device on my machine.
https://reactnative.dev/docs/running-on-simulator-ios
"react-native run-ios --simulator='iPhone 11 Pro'"
To list all devices
xcrun simctl list devices

Unable to boot device in current state: Booted

Any guess on "Unable to boot device in current state: Booted" error in Xcode6 beta while running (build+run) project in Simulator. I am just running my existing project in Xcode 6 I found above message. I tried cleaning, deleting of the derived data, even restarting the simulator doesn't work. Finally i restarted my Xcode 6 then it is working. Any simpler way to resolve the error instead of restarting your xcode6.
In Xcode go to the Xcode menu->Open Developer Tool - IOS Simulators. Choose simulator and then go hardware->device->manage device.
If the troubled device shows in the left column, delete it. Then add the device back from the '+' button. If it wasn't there in the first place, simply add it using the '+' button.
From terminal, get the list of devices with:
xcrun simctl list
This will show you your list of devices with "Shutdown" or "Booted". You'll likely see your device is in a "Booted" state. You can shut it down with:
xcrun simctl shutdown <simulator id>
Where <simulator id> is the name of the device in the list. For example:
xcrun simctl shutdown "iPhone 6 Plus"
2022 fix
I found solution. Simulator -> Preferences -> Simulator lifetime: When Simulator starts boot the most recently used simulator I unchecked.
This will kill any booted/running simulators even if the .app is not shown:
xcrun simctl shutdown all
I encountered similar problem. Got it resolved. Below are steps to fix it.
Open Simulator
Select Hardware -> Device -> Manage Devices...
This will opens a window containing list of simulator devices
Delete simulator that prompts error by right click on it.
Again add simulator by clicking '+' button onto right corner of window
Select Simulator Name, Device Type and iOS Version
Restarting the computer solved this for me. I restart very rarely so I would never normally have thought of this!
I solved this issue by this way:
Open Xcode
Goto Xcode menu > Open Developer Tool > iOS Simulators
It will run Simulator with error
Goto Hardware > Device > Manage Device
Add needed simulator to your system
This solution worked for me
Go to Xcode -> Open Developer Tool-> Simulator -> uncheck the option when simulator starts boot the most recently used simulator
Delete all devices on Simulator->Hardware, and add them back, not working :(
Bug or not, restarting Xcode doesn't work for me; could not get Simulator back to work until restarting my computer and it seems the adding-back had failed before restarting.
Quit iOS simulator. Change Target iOS Simulator to any other iPhone or iPad and then run app. Its working for me.
Applicable for Xcode 6.x, here is the command-line solution (type on Terminal window):
xcrun simctl shutdown
xcrun simctl erase
open /Contents/Developer/Applications/iOS\ Simulator.app
Where is the id of the device you want to launch. You can get the list of devices and their UDIDs here:
xcrun simctl list
I had the same problem. I reset the settings on the iOS Simulator, and run an xcrun simctl erase all and got the simulator working again.
Quit Xcode and Simulator.Then rebuild build and run.
Happened to me also, run an xcrun simctl shutdown <simulator uid> and got the simulator working again.
I don't know if this is any help to you guys but in my case I had this issue when I had a simulator window already open and I tried the command line invocation of simulator to run a .app file.
/Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/Contents/MacOS/iOS\ Simulator -SimulateApplication ${pathToMyApp}/MyApp.app/MyApp
I just quit all of my simulator windows and ran the command again. That fixed it.
I had the same problem. I reset the settings on the iOS Simulator, and it was fine again.
iOS Simulator -> Reset Content and Settings...
When I came to this issue,I tried to tackle it as follows:
cd /Applications/Xcode.app/Contents/Developer/Applications
In Terminal: open -n Simulator.app.Click Ok.
Then go to Simulator->hardware->Device choose another device,not the same type of already opened one.(e.g, the first one is iphone 6 the new one could be iphone 7)
4.Then there will open a new simulator.
Hope this will help you.
I just quit the Xcode and then remove all derrived data. Then relaunch Xcode and do cleaning, build it wait for it's indexing complete then run the project and issue get resolved.
With simulator opened, select "simulator preferences" and disable (simulator lifetime),so it doesn't use the same simulator used before the default.
Resolved for me.

When Running App in Simulator Xcode Gets Pushed to a Background Window

Whenever I build and run just this one particular app in XCode, the UI window of XCode gets pushed back underneath all existing running windows on OSX ( behind the browser and textedit etc...). This means I can't see the Xcode console debug outputs while playing with the app in the simulator. I feel like this could just be a quick setting in xcode or osx but I'm not sure why and how to fix this.
Use Spaces and develop with Xcode in its own virtual window. You will have just Xcode and Simulator wrestling for screen space then.
I normally have at least 5 windows open in Spaces:
Mail and Skype.
Web Browser
Xcode
Terminal/Finder/Odds and sods
Spare
Use Ctrl+Left and Ctrl+Right to switch windows.

Reset iOS Simulator application data to run app for first time

I just finished writing some code that checks if it is the first time the app is running then display a message, if it is not the first time then display another message..
How do you reset the simulator on Xcode so that I can test the app when it runs the first time?
I tried cleaning the build folder but it didn't work..
In the iOS Simulator, press iOS Simulator in the menu at the top of the screen, and press 'Reset Content and Settings...'. This will clear the entire simulator.
Or, on the home screen of the simulator, uninstall the app in the same way you would on a physical device, by pressing and holding on the application icon until an 'x' appears in the top left, and press the 'x', and select 'Delete' from the alert view. This will clear all data associated with a single app.
Then do a clean, build and run.
Edit:
As of Xcode 11+ Simulator, this is under Device > Erase All Content and Settings
The correct way to do this in XCode is: (Simulator must be shut down first)
xcrun simctl erase <device UDID>
or
xcrun simctl erase all
To find out the UDID use:
xcrun simctl list
Currently (Simulator Version 10.0), you can do it the following way:
Hardware > Erase All Content and Settings...
#Tim's answer is probably easier for interactive usage.
We use scripts for automated testing and delete the simulator's data directory to ensure it's clean. The simulator will re-create basic information when it restarts.
Delete the following:
~/Library/Application Support/iPhone Simulator/${simulator.version}
Don't really know if this is the best way but following is working for me:
first kill all working Simulators with
killall Simulator 2>&- && sleep 5 || true
afterwards reset all devices with
xcrun simctl erase all
ps.: I'm working with XCode 8
All of the answers are how to delete an app, or how to erase all simulator content and settings. If you want to delete just content and settings for specific simulator app find the following folder and delete it:
~/Library/Developer/CoreSimulator/Devices/{DEVICE_UDID}/data/Containers/Data/Application/{APP_UDID}
Where {DEVICE_UDID} is identifier for specific simulator and {APP_UDID} is identifier for specific app.

Xcode Doesn't Recognize My Device After OS Upgrade

This has to be a simple configuration issue, but I don't know my way around the build settings very well.
I upgraded my iPad from 4.3 to 5.0. I am using Xcode 4.2. When I plug my device in, it is not showing up on run button, and I have a message that it can't run using the selected device.
What do I have to do?
Open Xcode, go to Window -> Organizer and find your device. Click the "Use for Development" button to get Xcode to recognise it again.
go to your iphone device, settings->Reset->Reset All Settings. Close Xcode, restart XCode, device should be in the list now.
Restarting USB process worked for me.
Run sudo pkill usbmuxd on terminal
or
Open Activity Monitor and select Disk by tapping from segment control and search usbmuxd, select the same and force quite/quite.
Note: before doing above stuff, remove device and quite Xcode.

Resources