How to Open the iOS Simulator in Development Mode
I find it handy to test my website in the iOS Simulator sometimes. Therefor i keep this npm script to make it easier. I use the concurrently
package to run multiple commands at once.
"scripts": {
"start": "npm run dev",
"start:withsimulator": "concurrently \"npm run dev\" \"npm run simulator\"",
"simulator": "xcrun simctl list devices | grep 'iPhone 14' | grep -q Booted || xcrun simctl boot 'iPhone 14' && open -a Simulator && sleep 5 && xcrun simctl openurl booted 'http://localhost:4600/'",
"dev": "astro dev --open --port 4600",
"build": "astro build",
"preview": "astro preview",
"astro": "astro",
}
Just an example
package.json
. I runnpm start:withsimulator
to launch both the development server and the iOS Simulator.
Summary
-
xcrun simctl list devices
Lists all available iOS Simulator devices. -
| grep 'iPhone 14'
Filters the list to only show entries containing “iPhone 14”. -
| grep -q Booted
Quietly checks if an iPhone 14 simulator is already in the “Booted” state (running). -
|| xcrun simctl boot 'iPhone 14'
If the iPhone 14 simulator is not booted, this boots it. -
&& open -a Simulator
Opens the Simulator app itself (so you can see it running). -
&& sleep 5
Waits 5 seconds to ensure the simulator is fully ready before continuing. -
&& xcrun simctl openurl booted 'http://localhost:4600/'
Opens the given URL (http://localhost:4600/
) inside the booted simulator’s Safari browser.