iphone Tech

Managing The Xcode Simulator Programmatically

Managing The Xcode Simulator Programmatically

The iOS Simulator is a good way to check watchOS, tvOS, and iOS apps when you’re writing them. The simplest strategy to work with the simulator is thru Xcode. However it’s also possible to use simctl for interacting with it, useful in automating QA operations when attainable. The simctl binary is situated at /Purposes/Xcode.app/Contents/Developer/usr/bin/simctl and sometimes accessed as a verb from the /usr/bin/xcrun command. 

First let’s record all of the simulators, executed utilizing the record command, referred to as by merely operating xcrun adopted by simctl for the kind of operation to be run after which the record command:

/usr/bin/xcrun simctl listing

The output exhibits a variety of gadget varieties, runtimes, and units, most of which ought to present as disconnected or shutdown:

== System Varieties ==

== Gadget Varieties ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
iPhone 6s (com.apple.CoreSimulator.SimDeviceType.iPhone-6s)
iPhone 6s Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6s-Plus)
iPhone 7 (com.apple.CoreSimulator.SimDeviceType.iPhone-7)
iPhone 7 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-7-Plus)
iPhone Eight (com.apple.CoreSimulator.SimDeviceType.iPhone-Eight)
iPhone Eight Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-Eight-Plus)
iPhone SE (com.apple.CoreSimulator.SimDeviceType.iPhone-SE)
iPhone X (com.apple.CoreSimulator.SimDeviceType.iPhone-X)
iPhone Xs (com.apple.CoreSimulator.SimDeviceType.iPhone-XS)
iPhone Xs Max (com.apple.CoreSimulator.SimDeviceType.iPhone-XS-Max)
iPhone Xʀ (com.apple.CoreSimulator.SimDeviceType.iPhone-XR)
iPad mini (Fifth era) (com.apple.CoreSimulator.SimDeviceType.iPad-mini–Fifth-generation-)
iPad Air (Third era) (com.apple.CoreSimulator.SimDeviceType.iPad-Air–Third-generation-)
iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)
iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)
iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)
iPad mini 2 (com.apple.CoreSimulator.SimDeviceType.iPad-mini-2)
iPad mini Three (com.apple.CoreSimulator.SimDeviceType.iPad-mini-Three)
iPad mini Four (com.apple.CoreSimulator.SimDeviceType.iPad-mini-Four)
iPad Air 2 (com.apple.CoreSimulator.SimDeviceType.iPad-Air-2)
iPad (Fifth era) (com.apple.CoreSimulator.SimDeviceType.iPad–Fifth-generation-)
iPad Professional (9.7-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Professional–9-7-inch-)
iPad Professional (12.9-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Professional)
iPad Professional (12.9-inch) (2nd era) (com.apple.CoreSimulator.SimDeviceType.iPad-Professional–12-9-inch—2nd-generation-)
iPad Professional (10.5-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Professional–10-5-inch-)
iPad (Sixth era) (com.apple.CoreSimulator.SimDeviceType.iPad–Sixth-generation-)
iPad Professional (11-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Professional–11-inch-)
iPad Professional (12.9-inch) (Third era) (com.apple.CoreSimulator.SimDeviceType.iPad-Professional–12-9-inch—Third-generation-)
Apple TV (com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p)
Apple TV 4K (com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-4K)
Apple TV 4K (at 1080p) (com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-1080p)
Apple Watch – 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm)
Apple Watch – 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm)
Apple Watch Collection 2 – 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Collection-2-38mm)
Apple Watch Collection 2 – 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Collection-2-42mm)
Apple Watch Collection Three – 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Collection-Three-38mm)
Apple Watch Collection Three – 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Collection-Three-42mm)
Apple Watch Collection Four – 40mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Collection-Four-40mm)
Apple Watch Collection Four – 44mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Collection-Four-44mm)
== Runtimes ==
iOS 12.2 (12.2 – 16E226) – com.apple.CoreSimulator.SimRuntime.iOS-12-2 
tvOS 12.2 (12.2 – 16L225) – com.apple.CoreSimulator.SimRuntime.tvOS-12-2 
watchOS 5.2 (5.2 – 16T224) – com.apple.CoreSimulator.SimRuntime.watchOS-5-2 
== Units ==
— iOS 12.2 —
    iPhone 5s (4A2CC670-55EF-4B36-896F-EC2009EDEC07) (Shutdown) 
    iPhone 6 (937105ED-AEF1-4487-B406-1795D9AD9243) (Shutdown) 
    iPhone 6 Plus (E4031984-D79E-4888-A104-0C6DA73EB67F) (Shutdown) 
    iPhone 6s (EA859DD2-D934-4CB1-B2D5-Zero55F1DF93FB9) (Shutdown) 
    iPhone 6s Plus (CFFD27D8-4FEE-4632-B3BB-8133DBF74925) (Shutdown) 
    iPhone 7 (66BE2C4D-CB66-4618-A95D-BF239C569965) (Shutdown) 
    iPhone 7 Plus (3C6B97F3-AF19-49A9-B400-09A5CBCCB3D6) (Shutdown) 
    iPhone Eight (2D18B685-A642-44E5-BF8E-6D09AB478B0F) (Shutdown) 
    iPhone Eight Plus (BF652604-8F18-457C-B111-E951E8B55947) (Shutdown) 
    iPhone SE (384E1A51-7354-4FAC-A1A8-CB2B9CC5D1CF) (Shutdown) 
    iPhone X (98DD2AEC-4566-4896-83E5-E0B8603FFE9E) (Shutdown) 
    iPhone Xs (02A90E87-B2C4-44FE-9477-DD9455D7CB0C) (Shutdown) 
    iPhone Xs Max (79F42764-5020-41EA-87C3-55C541A790F5) (Shutdown) 
    iPhone Xʀ (AD6FD253-20A7-432C-8C22-5070489E787E) (Shutdown) 
    iPad Air (Third era) (DAB405D3-C1FD-47ED-B4FE-F0E1857A2862) (Shutdown) 
    iPad Air (3216E338-D522-43C7-9484-D7AEA081E926) (Shutdown) 
    iPad Air 2 (6B0BCC75-0ED6-4FC9-94C5-48A3466B79AD) (Shutdown) 
    iPad (Fifth era) (24313239-A853-46EB-B5A3-0DD8A86080F2) (Shutdown) 
    iPad Professional (9.7-inch) (8E2BEE13-D726-4CF5-8388-0913B87495F1) (Shutdown) 
    iPad Professional (12.9-inch) (9493C54B-D61E-4D42-8952-A89C2CCF2FDD) (Shutdown) 
    iPad Professional (12.9-inch) (2nd era) (5D978189-856D-4598-8C09-876BD832C71F) (Shutdown) 
    iPad Professional (10.5-inch) (2BF88E18-8C89-4515-A486-DC72C7A8629E) (Shutdown) 
    iPad (Sixth era) (Zero16DAA95-D917-4CD9-9A54-700D01BAF1AE) (Shutdown) 
    iPad Professional (11-inch) (307BEEDD-8652-4438-944B-CB423A26CC9E) (Shutdown) 
    iPad Professional (12.9-inch) (Third era) (D893291C-F214-4B43-A54F-3AB95A5442ED) (Shutdown) 
— tvOS 12.2 —
    Apple TV (1562B2B3-F403-4C99-8026-20AA51C8716B) (Shutdown) 
    Apple TV 4K (6C5CC68C-4C01-4097-91B8-A503B465F961) (Shutdown) 
    Apple TV 4K (at 1080p) (B8DCEFC3-F5BC-455D-B8B7-BAE7A48BE032) (Shutdown) 
— watchOS 5.2 —
    Apple Watch Collection 2 – 38mm (06938C62-9757-4F5E-913F-F9639D8AFF9C) (Shutdown) 
    Apple Watch Collection 2 – 42mm (BBA6DFC3-BC5A-494F-AFF4-E2B1331AFC69) (Shutdown) 
    Apple Watch Collection Three – 38mm (2D70BA7B-66BF-43E1-9F80-20EEFF588BB5) (Shutdown) 
    Apple Watch Collection Three – 42mm (F0E4E11E-639C-4F45-974A-2AAC684F1411) (Shutdown) 
    Apple Watch Collection Four – 40mm (B0CC419F-220F-46E1-B827-B512B08552B6) (Shutdown) 
    Apple Watch Collection Four – 44mm (7DAE1296-C9FF-4759-A066-1BA42A259853) (Shutdown) 
== System Pairs ==
620743A8-FD31-408C-AEBF-8D0F0849BD9D (lively, disconnected)
    Watch: Apple Watch Collection Four – 40mm (B0CC419F-220F-46E1-B827-B512B08552B6) (Shutdown)
    Telephone: iPhone Xs (02A90E87-B2C4-44FE-9477-DD9455D7CB0C) (Shutdown)
20E13C7F-3788-4DA5-962A-FF1389CDDA12 (lively, disconnected)
    Watch: Apple Watch Collection Four – 44mm (7DAE1296-C9FF-4759-A066-1BA42A259853) (Shutdown)
    Telephone: iPhone Xs Max (79F42764-5020-41EA-87C3-55C541A790F5) (Shutdown)

Subsequent, let’s create a recent new spiffy simulator referred to as testing_iPhone7. To take action we’ll 

/usr/bin/xcrun simctl create testing_iPhone7 com.apple.CoreSimulator.SimDeviceType.iPhone-7 com.apple.CoreSimulator.SimRuntime.iOS-12-2

The output features a UUID comparable to the next. That may then be used to trace additional interactions with the simulation:

E6D4C2B8-0601-4557-99DA-B6B8251D534D

The most typical duties can be booting, shutting down, erasing, and opening simulations. First let’s boot it up:

/usr/bin/xcrun simctl boot E6D4C2B8-0601-4557-99DA-B6B8251D534D

To close that very same simulator down use the shutdown verb:

/usr/bin/xcrun simctl shutdown E6D4C2B8-0601-4557-99DA-B6B8251D534D

Neither of those instructions present any output on success, however do error on failure. When you’ve run exams, I wish to erase my simulator and begin recent. To take action, merely use the erase command:

/usr/bin/xcrun simctl erase E6D4C2B8-0601-4557-99DA-B6B8251D534D

To open the simulator you loaded, you should use the open Simulator.app :

open /Purposes/Xcode.app/Contents/Developer/Purposes/Simulator.app/

Simulator App

For extra info on utilizing simctl subcommands, use the assistance subcommand:

/usr/bin/xcrun simctl assist

Discover there are plenty of verbs, which I’ll cowl additional in later articles:

create              Create a brand new system.

clone               Clone an present gadget.
improve             Improve a tool to a more moderen runtime.
delete              Delete a tool or all unavailable units.
pair                Create a brand new watch and telephone pair.
unpair              Unpair a watch and telephone pair.
pair_activate       Set a given pair as lively.
erase               Erase a tool’s contents and settings.
boot                Boot a tool.
shutdown            Shutdown a tool.
rename              Rename a tool.
getenv              Print an surroundings variable from a operating system.
openurl             Open a URL in a tool.
addmedia            Add photographs, reside photographs, movies, or contacts to the library of a tool.
set up             Set up an app on a tool.
uninstall           Uninstall an app from a tool.
get_app_container   Print the trail of the put in app’s container
launch              Launch an software by identifier on a tool.
terminate           Terminate an software by identifier on a tool.
spawn               Spawn a course of by executing a given executable on a tool.
record                Listing out there units, system varieties, runtimes, or gadget pairs.
icloud_sync         Set off iCloud sync on a tool.
pbsync              Sync the pasteboard content material from one pasteboard to a different.
pbcopy              Copy normal enter onto the gadget pasteboard.
pbpaste             Print the contents of the gadget’s pasteboard to plain output.
assist                Prints the utilization for a given subcommand.
io                  Arrange a tool IO operation.
diagnose            Acquire diagnostic info and logs.
logverbose          allow or disable verbose logging for a tool

Subsequent up, we’ll take a look at performing duties within the Simulator within the subsequent article on regression testing with the Simulator app.

(perform(d,s,id)var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))returnjs=d.createElement(s);js.id=id;js.src=”http://connect.facebook.net/en_US/all.js”;fjs.parentNode.insertBefore(js,fjs)(document,”script”,”facebook-jssdk”));