What this guide covers
When you finish, you can prepare a clean simulator and run tests on it using only Terminal, and clear out devices and runtimes you no longer use. You need: Xcode installed and at least one iOS simulator runtime.
Steps
First see what is on the machine
xcrun simctl list devices available xcrun simctl list runtimes xcrun simctl list devicetypesThe first lists the simulators currently available and their state, the second lists installed runtimes, and the third lists the device types you can create. Add
-jfor JSON output, which is easier for scripts to parse.Install a runtime
If the iOS version you need is missing, follow Apple's component installation documentation: click Get in Components under Xcode > Settings, or:
xcodebuild -downloadPlatform iOSThe documentation also says you can use
-buildVersionto specify the OS version and-exportPathto download without installing. Runtime files are large and download speed depends on the line, so run it inside tmux.Create a dedicated simulator
xcrun simctl create "ci-phone" <device type identifier> <runtime identifier>Take the two identifiers from the output of
list devicetypesandlist runtimes. Creating one device just for CI with a fixed name gives you more control than using the batch Xcode generates automatically: test scripts can find it by name and will not fail because the default devices changed after an Xcode upgrade.Boot, install the app, run
xcrun simctl boot "ci-phone" xcrun simctl install booted build/App.app xcrun simctl launch booted com.example.appbootedstands for the currently booted device. When several are booted, simctl picks one itself, so scripts are better off naming the device or its identifier. For running tests, hand over toxcodebuild testwith the destination written as-destination 'platform=iOS Simulator,name=ci-phone'.Erase before each test round
xcrun simctl shutdown all xcrun simctl erase "ci-phone"eraseclears the device's contents and settings, the equivalent of a factory reset. When test results are affected by data left over from the previous round, this is the most direct fix.Clean up unused devices and runtimes
xcrun simctl delete unavailable xcrun simctl runtime list xcrun simctl runtime delete <runtime identifier>delete unavailabledeletes devices the current Xcode no longer supports.runtime deletealso supports--notUsedSinceDays <days>to clean up by last use, and--dry-runshows what would be deleted without deleting it. Remember to run a cleanup after upgrading or removing an Xcode.Limits on remote and build machines
A simulator is not a real device. Push notifications, the camera and some hardware-related capabilities have to be verified on a real device, and a remote Mac cannot be connected to the device in your hand; see can a remote Mac debug on a real device.
When you watch the simulator over remote desktop, smoothness depends on your local network connection. CI tests do not need the picture and are unaffected. Also, simulators need a graphical session: the official GitLab Runner documentation points out that the runner has to run in a user session to access simulators. So a build agent should be installed as a service under the logged-in user.
FAQ
Why does the remote desktop get laggy after a simulator boots?
A simulator's picture changes a lot, so the amount of data the remote session sends goes up. If you only run automated tests, there is no need to open the Simulator app window; boot the device from the command line.
simctl says the device cannot be found. Why?
Use list first to confirm the name and state. A common cause is that you switched Xcode versions and the original device became unavailable under the new version. Create a new one.
Can I run several simulators at once?
Yes, but each one uses memory and CPU. How many can run in parallel depends on the machine configuration and your tests, and we have no measured figures to offer. See the plans page for configurations.
Do I need to clean up simulators before the rental ends?
Not for the sake of reclamation; the whole machine is erased. What you need to take with you are result files produced by tests, such as screenshots and logs, if they exist only on this machine.
Related
- Is Xcode laggy on a remote Mac?
- Can I debug on a real iPhone with a remote Mac?
- Xcode filled up my disk: how to clear DerivedData and what else is safe to delete
- Rented Mac mini as an always-on build machine for small teams? Count your build minutes first
- Install Xcode on a remote Mac: App Store or Apple Developer download?
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support