Batikan Sosun
Sahibinden Technology
9 min readMar 28, 2022

--

Become an iOS Simulator Master-Part 2

Take control over the Xcode simulator.

Before starting this article, if you haven’t read the previous part yet, I strongly recommend you do it.

The previous part is here:

In this article, I’m intending that I will be explaining the rest of the Simctl subcommands.

Let’s get this party started.

getenv — Simulator Environment Variables

The getenv subcommand prints an environment variable from a running device.

This command will print a UDID such as “C51B8057–4EF9–4C09-ADFE-1DCD83663C78”.

openurl — Pass a Deeplink Into the Simulator

openurl is a useful command to pass deep linking or universal links to the app.

openurl scheme

addMedia — Add Photos or Videos to the Simulator

You can add photos, live photos, videos, or contacts to the library of a device.

You can specify multiple files including a mix of photos, videos, and contacts.

You can also specify multiple live photos by providing the photo and video files. They will automatically be discovered and imported correctly.

Contacts support the vCard format.

You can verify the execution: visit the photo library and see it.

install — Install An App on The Simulator

This command is pretty good. The install command is installing an app on a device by app name from the given path. If you haven’t installed the application on the simulator yet and you have an application package, this command will save you.

uninstall — Uninstall an App on the Simulator

uninstall command is the opposite of the install command. Sure, you don’t need the simulator to uninstall an app.

get_app_container — Find the Documents Folder

get_app_container gets the path of the installed app’s container.

Parameters description is placed below.

container: Optionally specify the container. Defaults to the app.
app: The .app bundle
data: The application’s data container
groups: The App Group containers . <group identifier> A specific App Group container

install_app_data

install_app_data command installs an xcappdata package to a device, replacing the current contents of the container.

launch — Launch an App on the Simulator

launch command is used to launch an application by application identifier in your simulator device.

Parameters description is placed below.

— console Block and print the application’s stdout and stderr to the current terminal. Signals received by Simctl are passed through to the application. (Cannot be combined with — stdout or — stderr)
— console-pty Block and print the application’s stdout and stderr to the current terminal via a PTY. Signals received by Simctl are passed through to the application. (Cannot be combined with — stdout or — stderr)
— stdout=<path> Redirect the application’s standard output to a file.
— stderr=<path> Redirect the application’s standard error to a file.
— terminate-running-process Terminate any running copy of the application.

Note: Log output is often directed to stderr, not stdout.

If you want to set environment variables in the resulting environment, set them in the calling environment with a SIMCTL_CHILD_ prefix.

terminate — Terminate an App from the Simulator

Terminate an application by identifier on a device. Pretty easy to use this command.

spawn — Make iOS Plugins

I like the spawn command due to that the spawn makes iOS simulator plugins a reality. In simple defining, Spawn is a process by executing a given executable on a device.

Parameters description is placed below.
The path to the executable is searched using the following rules:
<path> contains no / characters: search the device’s $PATH. This is similar to how most shells work but searches the device’s path instead of the host’s path.
<path> starts with /: Assume a literal path to the binary. This must start from the host’s root.
<path> contains non-leading / characters: search relative to the current directory first, then relative to the device’s $SIMULATOR_ROOT.

If you want to set environment variables in the resulting environment, set them in the calling environment with a SIMCTL_CHILD_ prefix.

pbcopy — Copy Any Content to the Simulator

This command is to copy standard input onto the device pasteboard.

diagnose — Access All Diagnostic Logs

diagnose command collect diagnostic information and logs.

Parameters description is placed below.

-b: Do NOT show the resulting archive in a Finder window upon completion.

-X: Run all diagnostics with no timeout. It ignores the — timeout value if it is specified.

— timeout: Specify a duration (in seconds) to wait for the log collection before timeout.

— output: Specify the output directory.

If not provided the temporary directory is used.

— no-archive: Do not create an archive, leave the collected files uncompressed.

— all-logs: Include all device logs, even for non-booted devices.

— data-container: Include booted device(s) data directory.

Warning: May include private information, app data containers,

and increases the size of the archive!

Default is NOT to collect the data container.

— udid: Collect diagnostics only from the specified device. This option

may be specified more than once to consider multiple devices.

The — all-logs option causes all — udid options to be ignored.

NOTE: If there are booted devices only logs from those devices are collected by default, otherwise — all-logs are assumed. More information can be collected from a booted device so you should prefer leaving affected simulators booted when running Simctl diagnoses.

NOTE: You can run ‘Simctl log verbose <device> enable’ to enable verbose logging and reboot the device before reproducing the problem and running ‘Simctl diagnoses’.

status_bar — Manage Simulator Status Bar

status_bar command is to set or clear status bar overrides. Finally, you can now also manipulate the status bar data. Sounds like a good feature this is.

Parameters description is placed below.

list: List existing overrides.

clear: Clear all existing status bar overrides.

override <override arguments>
Set status bar override values, according to these flags.
You may specify any combination of these flags (at least one is required):

— time <string>
Set the date or time to a fixed value.
If the string is a valid ISO date string it will also set the date on relevant devices.
— dataNetwork <dataNetworkType>
If specified must be one of ‘hide’, ‘wifi’, ‘3g’, ‘4g’, ‘lte’, ‘lte-a’, ‘lte+’, ‘5g’, ‘5g+’, or ‘5g-uwb’.
— wifiMode <mode>
If specified must be one of ‘searching’, ‘failed’, or ‘active’.
— wifiBars <int>
If specified must be 0–3.
— cellularMode <mode>
If specified must be one of ‘notSupported’, ‘searching’, ‘failed’, or ‘active’.
— cellularBars <int>
If specified must be 0–4.
— operatorName <string>
Set the cellular operator/carrier name. Use ‘’ for the empty string.
— batteryState <state>
If specified must be one of ‘charging’, ‘charged’, or ‘discharging’.
— batteryLevel <int>
If specified must be 0–100.

ui— Change Simulator Appearance to Dark or Light Mode

UI command is one of the most popular the Simctl commands. This command executes a process for getting or setting UI options. You can change the simulator’s appearance to dark and light mode.

Parameters description is placed below.
appearance: When invoked without arguments prints the current user interface appearance style:

light: The Light appearance style.
dark: The Dark appearance style.
unsupported: The platform or runtime version does not support appearance styles.
unknown: The current style is unknown or there was an error detecting it.

appearance [light | dark]
Set the user interface appearance style to light or dark.

increase_contrast: When invoked without arguments prints whether the Increase Contrast mode is currently enabled:
enabled: Increase Contrast is enabled.
disabled:Increase Contrast is disabled.
unsupported: The platform or runtime version does not support the Increase Contrast setting.
unknown: The current setting is unknown or there was an error detecting it.

increase_contrast [enabled | disabled]
Enable or disable Increase Contrast mode.

content_size: When invoked without arguments prints the current preferred content size category, from the following possible values:
Standard sizes: extra-small, small, medium, large, extra-large, extra-extra-large, extra-extra-extra-large.
Extended range sizes: accessibility-medium, accessibility-large, accessibility-extra-large, accessibility-extra-extra-large, accessibility-extra-extra-extra-large.
Other values: unknown, unsupported.

content_size [increment | decrement | desired_size]
Set the preferred content size category. If ‘increment’ or ‘decrement’ is passed, the preferred content size will be set to the category one increment larger or smaller than the currently set value respectively.

push — Send Push Notification Through Terminal

You don’t need a server to trigger a push notification anymore. As I mentioned below article, you have other options to send a push notification. Now, you can do it with the Simctl push subcommand.

push

privacy — Manage Privacy Permissions

One of the best subcommands of Simctl is privacy. You can manage privacy permissions with Simctl. In this context, Simctl is pretty good capable to execute the privacy command.

You can edit the permissions such as location and notification that we often request from the user here.
Parameters description is placed below.
action: The action to take:
grant — Grant access without prompting. Requires bundle identifier.
revoke — Revoke access, denying all use of the service. Requires bundle identifier.
reset — Reset access, prompting on next use. Bundle identifier optional.
Some permission changes will terminate the application if running.
service: The service:
all — Apply the action to all services.
calendar — Allow access to the calendar.
contacts-limited — Allow access to basic contact info.
contacts — Allow access to full contact details.
location — Allow access to location services when the app is in use.
location-always — Allow access to location services at all times.
photos-add — Allow adding photos to the photo library.
photos — Allow full access to the photo library.
media-library — Allow access to the media library.
microphone — Allow access to audio input.
motion — Allow access to motion and fitness data.
reminders — Allow access to reminders.
Siri — Allow use of the app with Siri.
bundle identifier: The bundle identifier of the target application.

io — Capture Video Recording from the Simulator

io is one of the most subcommands I used. I use this command to record a video or take a screenshot.
Parameters description is placed below.

enumerate [ — poll]: Lists all available IO ports and descriptor states.
— poll Poll after enumeration.

poll: Polls are all available IO ports for events.

recordVideo [ — codec=<codec>] [ — display=<display>] [ — mask=<policy>] [ — force] <file or url>
Records the display to a QuickTime movie at the specified file or URL.
— codec Specifies the codec type: “h264” or “hevc”. Default is “hevc”.

— display iOS: supports “internal” or “external”. Default is “internal”.
tvOS: supports only “external”
watchOS: supports only “internal”

— mask For non-rectangular displays, handle the mask by policy:
ignored: The mask is ignored and the unmasked frame buffer is saved.
alpha: Not supported, but retained for compatibility; the mask is rendered black.
black: The mask is rendered black.

— force Force the output file to be written to, even if the file already exists.

screenshot [ — type=<type>] [ — display=<display>] [ — mask=<policy>] <file or url>
Saves a screenshot as a PNG to the specified file or url(use “-” for stdout).
— type Can be “png”, “tiff”, “bmp”, “gif”, “jpeg”. Default is png.

— display iOS: supports “internal” or “external”. Default is “internal”.
tvOS: supports only “external”
watchOS: supports only “internal”

You may also specify a port by UUID
— mask For non-rectangular displays, handle the mask by policy:
ignored: The mask is ignored and the unmasked frame buffer is saved.
alpha: The mask is used as premultiplied alpha.
black: The mask is rendered black.

keychain — Install Certificate

One more command, you can also install certificates using the new keychain subcommand.

add-root-cert [path]: Add a certificate to the trusted root store.

add-cert [path]: Add a certificate to the keychain.

reset: Reset the keychain.

Thanks for reading, Have a nice day 🙌

Click Here for Github Gist of the examples.

--

--

Batikan Sosun
Sahibinden Technology

Tweeting tips and tricks about #swift #xcode #apple Twitter @batikansosun Weekly Swift Blogging