iOS 模拟器管理工具 simctl

发布于 2021-03-24 21:46:57 字数 32550 浏览 2530 评论 0

苹果提供了一个命令行工具来与iOS模拟器进行交互。在 Applications/Xcode.app/Contents/Developer/usr/bin/simctl 路径下,通过 xcrun 命令访问。

1.打开模拟器应用

open "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/"

2.该命令所有的功能选项

xcrun simctl help

➜  ~ xcrun simctl help
usage: simctl [--set <path>] [--profiles <path>] <subcommand> ...
       simctl help [subcommand]
Command line utility to control the Simulator

For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.

Subcommands:
	create              Create a new device.
	clone               Clone an existing device.
	upgrade             Upgrade a device to a newer runtime.
	delete              Delete a device or all unavailable devices.
	pair                Create a new watch and phone pair.
	unpair              Unpair a watch and phone pair.
	pair_activate       Set a given pair as active.
	erase               Erase a device's contents and settings.
	boot                Boot a device.
	shutdown            Shutdown a device.
	rename              Rename a device.
	getenv              Print an environment variable from a running device.
	openurl             Open a URL in a device.
	addmedia            Add photos, live photos, videos, or contacts to the library of a device.
	install             Install an app on a device.
	uninstall           Uninstall an app from a device.
	get_app_container   Print the path of the installed app's container
	launch              Launch an application by identifier on a device.
	terminate           Terminate an application by identifier on a device.
	spawn               Spawn a process by executing a given executable on a device.
	list                List available devices, device types, runtimes, or device pairs.
	icloud_sync         Trigger iCloud sync on a device.
	pbsync              Sync the pasteboard content from one pasteboard to another.
	pbcopy              Copy standard input onto the device pasteboard.
	pbpaste             Print the contents of the device's pasteboard to standard output.
	help                Prints the usage for a given subcommand.
	io                  Set up a device IO operation.
	diagnose            Collect diagnostic information and logs.
	logverbose          enable or disable verbose logging for a device
子命令功能
create新建一个新的模拟器
clone克隆一个已有的模拟器
upgrade给模拟器升级系统
delete删除一个模拟器或删除全部不可用模拟器
pair将手表模拟器和iPhone模拟器进行配对
unpair解除手表模拟器和iPhone模拟器的配对
pair_activate激活手表模拟器和iPhone模拟器的配对
erase清除模拟器的所有数据和设置
boot启动一个模拟器
shutdown关闭一个模拟器
rename重命名模拟器
getenv获取模拟器环境变量对应的值
openurl打开一个链接(不局限于网页链接)
addphoto给模拟器相册中添加照片
addvideo给模拟器相册中添加视频
addmedia给模拟器相册中添加照片、LIVE照片或者视频
install安装一个应用
uninstall卸载一个应用
get_app_container获取应用的沙盒路径
launch打开一个应用
terminate关闭一个应用
spawn开启一个新进程
list列出所有可用的模拟器、模拟器类型、系统版本、设备配对情况
icloud_sync触发设备上的iCloud同步
pbinfo打印模拟器粘贴板的信息
pbsync将设备粘贴板的信息同步给其他设备
pbcopy将标准输入复制到设备粘贴板上
pbpaste将设备的剪切板打印到标准输出中
notify_post发送一个Darwin通知
notify_get_state设置Darwin通知的状态值
notify_set_state获取Darwin通知的状态值
register注册一个服务
unregister注销一个服务
keyboard设置键盘的主语言
monitor当通知达到的时候,打印出来
appinfo获取一个已安装app的信息
listapps获取全部已安装的app
help显示如何使用
io设置设备IO操作
diagnose收集诊断信息和日志
logverbose启用或禁用设备的详细日志记录
bootstatus检查设备的运行状态
darwinup调用darwinup来安装一个root运行环境

3.列出所有可用的模拟器

列出所用可用的模拟器

xcrun simctl list

➜  ~ xcrun simctl list
== Device Types ==
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 8 (com.apple.CoreSimulator.SimDeviceType.iPhone-8)
iPhone 8 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-8-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 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 3 (com.apple.CoreSimulator.SimDeviceType.iPad-mini-3)
iPad mini 4 (com.apple.CoreSimulator.SimDeviceType.iPad-mini-4)
iPad Air 2 (com.apple.CoreSimulator.SimDeviceType.iPad-Air-2)
iPad Pro (9.7-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-)
iPad Pro (12.9-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro)
iPad (5th generation) (com.apple.CoreSimulator.SimDeviceType.iPad--5th-generation-)
iPad Pro (12.9-inch) (2nd generation) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--12-9-inch---2nd-generation-)
iPad Pro (10.5-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--10-5-inch-)
iPad (6th generation) (com.apple.CoreSimulator.SimDeviceType.iPad--6th-generation-)
iPad Pro (11-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--11-inch-)
iPad Pro (12.9-inch) (3rd generation) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--12-9-inch---3rd-generation-)
iPad mini (5th generation) (com.apple.CoreSimulator.SimDeviceType.iPad-mini--5th-generation-)
iPad Air (3rd generation) (com.apple.CoreSimulator.SimDeviceType.iPad-Air--3rd-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 Series 2 - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-38mm)
Apple Watch Series 2 - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-42mm)
Apple Watch Series 3 - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-38mm)
Apple Watch Series 3 - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-42mm)
Apple Watch Series 4 - 40mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-4-40mm)
Apple Watch Series 4 - 44mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-4-44mm)
== Runtimes ==
iOS 12.1 (12.1 - 16B91) - com.apple.CoreSimulator.SimRuntime.iOS-12-1
iOS 12.4 (12.4 - 16G73) - com.apple.CoreSimulator.SimRuntime.iOS-12-4
tvOS 12.4 (12.4 - 16M567) - com.apple.CoreSimulator.SimRuntime.tvOS-12-4
watchOS 5.3 (5.3 - 16U567) - com.apple.CoreSimulator.SimRuntime.watchOS-5-3
== Devices ==
-- iOS 12.1 --
    iPhone 5s (D18344D8-537A-4768-B632-5FE7ADF56A30) (Shutdown)
    iPhone 6 (6413C54A-B58D-4766-88E4-09217AFE1D1F) (Shutdown)
    iPhone 6 Plus (6E56A264-8232-4800-8A11-DC5FE00BFF48) (Shutdown)
    iPhone 6s (FCD3DF81-083C-48A4-95E5-028164457FF7) (Shutdown)
    iPhone 6s Plus (037A4CBC-3E62-48D1-9B0B-DFF0DE34D91C) (Shutdown)
    iPhone 7 (BC8652C8-52BE-4A25-99E9-7C9DF8540EEF) (Shutdown)
    iPhone 7 Plus (A6763C3B-8F18-4F9C-8BF3-8FFA8DB03215) (Shutdown)
    iPhone 8 (7979F875-178F-49B6-B58A-ADEFFE734876) (Shutdown)
    iPhone 8 Plus (5254D90C-CD43-4214-9E2A-6D662A612116) (Shutdown)
    iPhone SE (B329A9DF-AFC3-4EB8-B78C-3489AD1CB49A) (Shutdown)
    iPhone X (0923A5A0-2C63-4E1D-A335-AD1FA670AB90) (Shutdown)
    iPhone XS (133503E1-85C6-417D-BF1B-5159390B22A7) (Shutdown)
    iPhone XS Max (A553F396-C2C4-4198-8EAE-04FC3E26DB87) (Shutdown)
    iPhone XR (BB694438-5CF4-4D79-8408-E20BA90C2539) (Shutdown)
    iPad Air (BE06F167-C7FE-4A89-8EBD-E1EA5E25BBA7) (Shutdown)
    iPad Air 2 (2CD9098A-1EA8-4888-B934-783844997B47) (Shutdown)
    iPad Pro (9.7-inch) (4AE32D3A-8133-450A-952E-CEA72E75431D) (Shutdown)
    iPad Pro (12.9-inch) (5D09C561-0634-42D4-8908-FB5C0252953D) (Shutdown)
    iPad (5th generation) (7F0DF067-AE97-4EB9-B036-0E15CC43E407) (Shutdown)
    iPad Pro (12.9-inch) (2nd generation) (4AD5E096-2D43-4E99-8144-90D5102CA797) (Shutdown)
    iPad Pro (10.5-inch) (90831EE4-4D4B-4B91-B1B5-9F8D3CA81DC4) (Shutdown)
    iPad (6th generation) (7704B040-BA5E-4466-834C-97A4FC7B7261) (Shutdown)
    iPad Pro (11-inch) (271CDAC5-61B8-4A40-B033-213C17268D79) (Shutdown)
    iPad Pro (12.9-inch) (3rd generation) (83372E70-A1FF-466D-8C17-F78B13A47AA8) (Shutdown)
-- iOS 12.4 --
    iPhone 5s (8FB762F8-0342-473B-B3AF-0B02611C15DC) (Shutdown)
    iPhone 6 (C6116152-DA4C-4465-B7F1-1A95DA5B0314) (Shutdown)
    iPhone 6 Plus (F8F09004-E9D8-4ED0-A885-7525827028AA) (Shutdown)
    iPhone 6s (8B5B8946-3584-4A2A-B7EA-9296C06E6E22) (Shutdown)
    iPhone 6s Plus (44EB04FC-28FF-4AB2-BCD0-CCFAE7944C27) (Shutdown)
    iPhone 7 (A3D7D835-03B1-420A-B5C9-C7FBB02DAB82) (Shutdown)
    iPhone 7 Plus (E602924D-3B08-4944-8621-E049AAB954A4) (Shutdown)
    iPhone 8 (B3286521-1453-4416-8E69-060EC7F15C9A) (Shutdown)
    iPhone 8 Plus (D4A4D32A-1863-499B-831B-F04682E80367) (Shutdown)
    iPhone SE (B8083540-E1FF-463D-9320-34AF368EE360) (Shutdown)
    iPhone X (32520069-2635-4C58-82FB-7C0A44D14EB3) (Shutdown)
    iPhone Xs (B4B292AA-FC9E-4D6E-A428-ED6187DDA6D0) (Shutdown)
    iPhone Xs Max (07E8A9A0-7DC9-4D13-B5FB-C5959B24B086) (Shutdown)
    iPhone Xʀ (3293BD4E-D013-490C-99B7-C4930067EDEA) (Shutdown)
    iPad Air (313CF167-743A-4B0D-B21E-B336A800BBFD) (Shutdown)
    iPad Air 2 (056333EA-33E1-4CA6-BAAD-C3C3B23BC0BE) (Shutdown)
    iPad Pro (9.7-inch) (20FADBA2-8FCD-4C60-BD47-E512012D6D0D) (Shutdown)
    iPad Pro (12.9-inch) (39E0DD7A-C79D-48B2-8B88-CC14A6D2A186) (Shutdown)
    iPad (5th generation) (24704681-4375-4728-BACF-96B47D09464B) (Shutdown)
    iPad Pro (12.9-inch) (2nd generation) (DE55DAAB-2615-495C-A14E-A097112B11D6) (Shutdown)
    iPad Pro (10.5-inch) (D4A45815-9A53-4BF6-88F1-FA63B15657BE) (Shutdown)
    iPad (6th generation) (131899C3-98CD-411F-9D40-6182B7305ED1) (Shutdown)
    iPad Pro (11-inch) (16487AC9-DB44-492C-874D-3CC060A05E51) (Shutdown)
    iPad Pro (12.9-inch) (3rd generation) (7E904FB1-BDC1-4152-A0AE-37EBB95CDABA) (Shutdown)
    iPad Air (3rd generation) (79E57342-EF49-4DCA-BFEC-264D9A99742E) (Shutdown)
-- tvOS 12.4 --
    Apple TV (1B8916EA-4806-4775-8623-239260793EBE) (Shutdown)
    Apple TV 4K (72F566B4-313D-41B8-83DB-5BF7994C07D4) (Shutdown)
    Apple TV 4K (at 1080p) (0BC8E6C0-E7C8-4BBB-94AA-76616B15F213) (Shutdown)
-- watchOS 5.3 --
    Apple Watch Series 2 - 38mm (E0302608-7AAB-438A-846B-7E8D2F3A642E) (Shutdown)
    Apple Watch Series 2 - 42mm (ED95358E-2C32-4721-A2F6-B76C01692C57) (Shutdown)
    Apple Watch Series 3 - 38mm (A0FF0B95-FE6E-4DDF-A344-F259B94204B0) (Shutdown)
    Apple Watch Series 3 - 42mm (684559E8-DBC1-4B0C-8DD6-C218ACC508E3) (Shutdown)
    Apple Watch Series 4 - 40mm (3DB7C038-A7FE-4DC1-B9A4-C0378366FE44) (Shutdown)
    Apple Watch Series 4 - 44mm (F23E7C7C-0B02-469C-84F8-B292B9DFE664) (Shutdown)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-12-2 --
    iPhone 5s (9BB31E5E-3345-4CE1-ACEA-0E66F689BF66) (Shutdown) (unavailable, runtime profile not found)
    iPhone 6 (660A6319-8524-45C4-9710-85A8733419E3) (Shutdown) (unavailable, runtime profile not found)
    iPhone 6 Plus (368408CC-01B1-4460-BE5D-635048233785) (Shutdown) (unavailable, runtime profile not found)
    iPhone 6s (B4311CAB-5664-4535-9C6B-60DDAF9D0D31) (Shutdown) (unavailable, runtime profile not found)
    iPhone 6s Plus (47205D96-88EF-4E13-B99D-1D496E508260) (Shutdown) (unavailable, runtime profile not found)
    iPhone 7 (0B377D3C-06F2-45A3-A62C-200C93854379) (Shutdown) (unavailable, runtime profile not found)
    iPhone 7 Plus (58FF7620-517E-4F14-BA1A-38DDBD2BBFB4) (Shutdown) (unavailable, runtime profile not found)
    iPhone 8 (01876873-921C-4916-993C-82E7EA86F835) (Shutdown) (unavailable, runtime profile not found)
    iPhone 8 Plus (7AF054B2-E74D-4E59-A0E0-EEEA182E3FD4) (Shutdown) (unavailable, runtime profile not found)
    iPhone SE (CF026A3F-8228-48A0-8611-CD75572B0D9E) (Shutdown) (unavailable, runtime profile not found)
    iPhone X (E767EE8F-AE2E-450B-8DBB-9D874F93D4E2) (Shutdown) (unavailable, runtime profile not found)
    iPhone Xs (2FC0621A-C32A-41A5-89B8-B24080777637) (Shutdown) (unavailable, runtime profile not found)
    iPhone Xs Max (11CCF28D-6D89-4049-85B6-3440006DFE82) (Shutdown) (unavailable, runtime profile not found)
    iPad Air (6E43F9C7-9C03-49CA-84C4-7F8DD490BA98) (Shutdown) (unavailable, runtime profile not found)
    iPad Air 2 (71285E0E-014E-441B-8A85-5B982BE77635) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (9.7-inch) (69DBEC64-D259-4A14-8C1B-8CFABDB4EF66) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (12.9-inch) (9220E112-546D-45CA-BCFD-939532A7E91B) (Shutdown) (unavailable, runtime profile not found)
    iPad (5th generation) (AF58CF2A-5754-4D6F-BA71-ECB4878403CD) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (12.9-inch) (2nd generation) (D688FC25-70A7-46A7-B577-D71DA6ECF3C1) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (10.5-inch) (A9E49675-DC2B-4EDC-9CB2-FE08963C9B65) (Shutdown) (unavailable, runtime profile not found)
    iPad (6th generation) (B83A6305-5EF5-40BD-B0E3-9FE412643B09) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (11-inch) (A2412F99-8511-47DE-8EFE-7E59DF66315C) (Shutdown) (unavailable, runtime profile not found)
    iPad Pro (12.9-inch) (3rd generation) (668F3F90-4374-450B-B007-0F3BFA93EB18) (Shutdown) (unavailable, runtime profile not found)
    iPad Air (3rd generation) (33C70CA3-AA14-40B5-B4A0-DD317545A332) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.tvOS-12-2 --
    Apple TV (CAA9BAB7-FB14-44B7-BE0C-8AD6AA3A4259) (Shutdown) (unavailable, runtime profile not found)
    Apple TV 4K (3485B6D1-0A88-435E-A62F-A013D583AF7E) (Shutdown) (unavailable, runtime profile not found)
    Apple TV 4K (at 1080p) (CE48A739-700A-4B03-BDB7-1E2C1087094F) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.watchOS-5-2 --
    Apple Watch Series 2 - 38mm (A4C4A1A4-7C5C-4E1A-A8AA-CBECDF534896) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 2 - 42mm (A1B04A70-3F2C-45EB-A738-E61944EF22AD) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 3 - 38mm (CC3ADDFB-8F15-46E9-BC70-E3779DA7E5F1) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 3 - 42mm (535AB975-7216-4171-8030-35C1C7EE30F7) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 4 - 40mm (A16FFD83-BA69-4759-94FC-97F212467CC3) (Shutdown) (unavailable, runtime profile not found)
    Apple Watch Series 4 - 44mm (F8B611AC-8A8F-476A-9FAC-44C8028D1232) (Shutdown) (unavailable, runtime profile not found)
== Device Pairs ==
41024403-FCD5-4D8E-84DF-B8664F9204A7 (active, disconnected)
    Watch: Apple Watch Series 4 - 40mm (3DB7C038-A7FE-4DC1-B9A4-C0378366FE44) (Shutdown)
    Phone: iPhone Xs (B4B292AA-FC9E-4D6E-A428-ED6187DDA6D0) (Shutdown)
2DFBBB40-C973-419A-8CA0-4811E46A9F9A (active, disconnected)
    Watch: Apple Watch Series 4 - 44mm (F23E7C7C-0B02-469C-84F8-B292B9DFE664) (Shutdown)
    Phone: iPhone Xs Max (07E8A9A0-7DC9-4D13-B5FB-C5959B24B086) (Shutdown)
E7CEF71D-B2AA-4BC5-83EB-039E6724C85D (unavailable)
    Watch: Apple Watch Series 4 - 40mm (A16FFD83-BA69-4759-94FC-97F212467CC3) (Shutdown)
    Phone: iPhone Xs (2FC0621A-C32A-41A5-89B8-B24080777637) (Shutdown)
2ADFDA44-A8B6-48A4-83B1-5672A3CD3726 (unavailable)
    Watch: Apple Watch Series 4 - 44mm (F8B611AC-8A8F-476A-9FAC-44C8028D1232) (Shutdown)
    Phone: iPhone Xs Max (11CCF28D-6D89-4049-85B6-3440006DFE82) (Shutdown)

-j或者--json参数,会以JSON的数据形式输出。每个设备都有一个关联的 UDID。

  ➜  ~ xcrun simctl list -j
{
  "devicetypes" : [
    {
      "name" : "iPhone 4s",
      "bundlePath" : "\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/Library\/CoreSimulator\/Profiles\/DeviceTypes\/iPhone 4s.simdevicetype",
      "identifier" : "com.apple.CoreSimulator.SimDeviceType.iPhone-4s"
    }....],
  "runtimes" : [
    {
      "version" : "12.1",
      "bundlePath" : "\/Library\/Developer\/CoreSimulator\/Profiles\/Runtimes\/iOS 12.1.simruntime",
      "isAvailable" : true,
      "name" : "iOS 12.1",
      "identifier" : "com.apple.CoreSimulator.SimRuntime.iOS-12-1",
      "buildversion" : "16B91"
    }...],
  "devices" : {
    "com.apple.CoreSimulator.SimRuntime.iOS-12-2" : [
      {
        "state" : "Shutdown",
        "isAvailable" : false,
        "name" : "iPhone 5s",
        "udid" : "9BB31E5E-3345-4CE1-ACEA-0E66F689BF66",
        "availabilityError" : "runtime profile not found"
      }...],
    "com.apple.CoreSimulator.SimRuntime.iOS-12-1" : [
      {
        "state" : "Shutdown",
        "isAvailable" : true,
        "name" : "iPhone 5s",
        "udid" : "D18344D8-537A-4768-B632-5FE7ADF56A30"
      }...]},
  "pairs" : {
    "2DFBBB40-C973-419A-8CA0-4811E46A9F9A" : {
      "watch" : {
        "name" : "Apple Watch Series 4 - 44mm",
        "udid" : "F23E7C7C-0B02-469C-84F8-B292B9DFE664",
        "state" : "Shutdown"
      },
      "phone" : {
        "name" : "iPhone Xs Max",
        "udid" : "07E8A9A0-7DC9-4D13-B5FB-C5959B24B086",
        "state" : "Shutdown"
      },
      "state" : "(active, disconnected)"
    }...}
}

xcrun simctl list | grep Booted :使用grep过滤已启动的devices

➜  ~ xcrun simctl list | grep Booted
 iPhone Xʀ (3293BD4E-D013-490C-99B7-C4930067EDEA) (Booted)

要隔离设备标识符,您可以grep再次重定向以搜索UDID模式

➜  ~ xcrun simctl list devices | \
    grep "(Booted)"         | \
    grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})"
6413C54A-B58D-4766-88E4-09217AFE1D1F
3293BD4E-D013-490C-99B7-C4930067EDEA

列出安装的可用的模拟器 xcrun instruments -s

➜  ~ xcrun instruments -s
CoreData: annotation:  Failed to load optimized model at path '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPackaging.framework/Versions/A/Resources/XRPackageModel.momd/XRPackageModel 9.0.omo'
Known Devices:
ZLL的MacBook Pro [ADF75579-BB74-5CCF-8FCD-EC215957B95E]
(null) [ab093d5bf4293ea662abe40b4ca5952410e0f662]
Apple TV (12.4) [1B8916EA-4806-4775-8623-239260793EBE] (Simulator)
Apple TV 4K (12.4) [72F566B4-313D-41B8-83DB-5BF7994C07D4] (Simulator)
Apple TV 4K (at 1080p) (12.4) [0BC8E6C0-E7C8-4BBB-94AA-76616B15F213] (Simulator)
Apple Watch Series 2 - 38mm (5.3) [E0302608-7AAB-438A-846B-7E8D2F3A642E] (Simulator)
Apple Watch Series 2 - 42mm (5.3) [ED95358E-2C32-4721-A2F6-B76C01692C57] (Simulator)
Apple Watch Series 3 - 38mm (5.3) [A0FF0B95-FE6E-4DDF-A344-F259B94204B0] (Simulator)
Apple Watch Series 3 - 42mm (5.3) [684559E8-DBC1-4B0C-8DD6-C218ACC508E3] (Simulator)
iPad (5th generation) (12.1) [7F0DF067-AE97-4EB9-B036-0E15CC43E407] (Simulator)
iPad (5th generation) (12.4) [24704681-4375-4728-BACF-96B47D09464B] (Simulator)
iPad (6th generation) (12.1) [7704B040-BA5E-4466-834C-97A4FC7B7261] (Simulator)
iPad (6th generation) (12.4) [131899C3-98CD-411F-9D40-6182B7305ED1] (Simulator)
iPad Air (12.1) [BE06F167-C7FE-4A89-8EBD-E1EA5E25BBA7] (Simulator)
iPad Air (12.4) [313CF167-743A-4B0D-B21E-B336A800BBFD] (Simulator)
iPad Air (3rd generation) (12.4) [79E57342-EF49-4DCA-BFEC-264D9A99742E] (Simulator)
iPad Air 2 (12.1) [2CD9098A-1EA8-4888-B934-783844997B47] (Simulator)
iPad Air 2 (12.4) [056333EA-33E1-4CA6-BAAD-C3C3B23BC0BE] (Simulator)
iPad Pro (10.5-inch) (12.1) [90831EE4-4D4B-4B91-B1B5-9F8D3CA81DC4] (Simulator)
iPad Pro (10.5-inch) (12.4) [D4A45815-9A53-4BF6-88F1-FA63B15657BE] (Simulator)
iPad Pro (11-inch) (12.1) [271CDAC5-61B8-4A40-B033-213C17268D79] (Simulator)
iPad Pro (11-inch) (12.4) [16487AC9-DB44-492C-874D-3CC060A05E51] (Simulator)
iPad Pro (12.9-inch) (12.1) [5D09C561-0634-42D4-8908-FB5C0252953D] (Simulator)
iPad Pro (12.9-inch) (12.4) [39E0DD7A-C79D-48B2-8B88-CC14A6D2A186] (Simulator)
iPad Pro (12.9-inch) (2nd generation) (12.1) [4AD5E096-2D43-4E99-8144-90D5102CA797] (Simulator)
iPad Pro (12.9-inch) (2nd generation) (12.4) [DE55DAAB-2615-495C-A14E-A097112B11D6] (Simulator)
iPad Pro (12.9-inch) (3rd generation) (12.1) [83372E70-A1FF-466D-8C17-F78B13A47AA8] (Simulator)
iPad Pro (12.9-inch) (3rd generation) (12.4) [7E904FB1-BDC1-4152-A0AE-37EBB95CDABA] (Simulator)
iPad Pro (9.7-inch) (12.1) [4AE32D3A-8133-450A-952E-CEA72E75431D] (Simulator)
iPad Pro (9.7-inch) (12.4) [20FADBA2-8FCD-4C60-BD47-E512012D6D0D] (Simulator)
iPhone 5s (12.1) [D18344D8-537A-4768-B632-5FE7ADF56A30] (Simulator)
iPhone 5s (12.4) [8FB762F8-0342-473B-B3AF-0B02611C15DC] (Simulator)
iPhone 6 (12.1) [6413C54A-B58D-4766-88E4-09217AFE1D1F] (Simulator)
iPhone 6 (12.4) [C6116152-DA4C-4465-B7F1-1A95DA5B0314] (Simulator)
iPhone 6 Plus (12.1) [6E56A264-8232-4800-8A11-DC5FE00BFF48] (Simulator)
iPhone 6 Plus (12.4) [F8F09004-E9D8-4ED0-A885-7525827028AA] (Simulator)
iPhone 6s (12.1) [FCD3DF81-083C-48A4-95E5-028164457FF7] (Simulator)
iPhone 6s (12.4) [8B5B8946-3584-4A2A-B7EA-9296C06E6E22] (Simulator)
iPhone 6s Plus (12.1) [037A4CBC-3E62-48D1-9B0B-DFF0DE34D91C] (Simulator)
iPhone 6s Plus (12.4) [44EB04FC-28FF-4AB2-BCD0-CCFAE7944C27] (Simulator)
iPhone 7 (12.1) [BC8652C8-52BE-4A25-99E9-7C9DF8540EEF] (Simulator)
iPhone 7 (12.4) [A3D7D835-03B1-420A-B5C9-C7FBB02DAB82] (Simulator)
iPhone 7 Plus (12.1) [A6763C3B-8F18-4F9C-8BF3-8FFA8DB03215] (Simulator)
iPhone 7 Plus (12.4) [E602924D-3B08-4944-8621-E049AAB954A4] (Simulator)
iPhone 8 (12.1) [7979F875-178F-49B6-B58A-ADEFFE734876] (Simulator)
iPhone 8 (12.4) [B3286521-1453-4416-8E69-060EC7F15C9A] (Simulator)
iPhone 8 Plus (12.1) [5254D90C-CD43-4214-9E2A-6D662A612116] (Simulator)
iPhone 8 Plus (12.4) [D4A4D32A-1863-499B-831B-F04682E80367] (Simulator)
iPhone SE (12.1) [B329A9DF-AFC3-4EB8-B78C-3489AD1CB49A] (Simulator)
iPhone SE (12.4) [B8083540-E1FF-463D-9320-34AF368EE360] (Simulator)
iPhone X (12.1) [0923A5A0-2C63-4E1D-A335-AD1FA670AB90] (Simulator)
iPhone X (12.4) [32520069-2635-4C58-82FB-7C0A44D14EB3] (Simulator)
iPhone XR (12.1) [BB694438-5CF4-4D79-8408-E20BA90C2539] (Simulator)
iPhone XS (12.1) [133503E1-85C6-417D-BF1B-5159390B22A7] (Simulator)
iPhone XS Max (12.1) [A553F396-C2C4-4198-8EAE-04FC3E26DB87] (Simulator)
iPhone Xs (12.4) [B4B292AA-FC9E-4D6E-A428-ED6187DDA6D0] (Simulator)
iPhone Xs (12.4) + Apple Watch Series 4 - 40mm (5.3) [3DB7C038-A7FE-4DC1-B9A4-C0378366FE44] (Simulator)
iPhone Xs Max (12.4) [07E8A9A0-7DC9-4D13-B5FB-C5959B24B086] (Simulator)
iPhone Xs Max (12.4) + Apple Watch Series 4 - 44mm (5.3) [F23E7C7C-0B02-469C-84F8-B292B9DFE664] (Simulator)
iPhone Xʀ (12.4) [3293BD4E-D013-490C-99B7-C4930067EDEA] (Simulator)
Known Templates:
"Activity Monitor"
"Allocations"
"Blank"
"Core Animation"
"Core Data"
"Counters"
"Energy Log"
"File Activity"
"Game Performance"
"Leaks"
"Metal System Trace"
"Network"
"SceneKit"
"System Trace"
"System Usage"
"Time Profiler"
"Zombies"

4.创建、删除、重命名、升级

创建: xcrun simctl create "<name>" "<SimDeviceType>" "<SimRuntime"

xcrun simctl create "my_iPhone_X" "com.apple.CoreSimulator.SimDeviceType.iPhone-X" "com.apple.CoreSimulator.SimRuntime.iOS-11-4"

重命名: xcrun simctl rename $UDID "new_name"

xcrun simctl rename "E3AEEEDA-00C7-4AB3-B634-760B0F838DE8" "new_iPhone"

删除: xcrun simctl delete $UDID

xcrun simctl delete "E3AEEEDA-00C7-4AB3-B634-760B0F838DE8"

升级: xcrun simctl upgrade $UDID

xcrun simctl upgrade "E3AEEEDA-00C7-4AB3-B634-760B0F838DE8"

: 可替换为相应的字符串,$UDID:可替换为设备的UDID。UDID加不加字符引号都可以,它们是连起来的整体。上下文都一致

5.启动、关闭、重置模拟器

启动 :

xcrun simctl boot $UDID
xcrun instruments -w "iPhone XS (12.1)"

关闭:

xcrun simctl shutdown $UDID
xcrun simctl shutdown all 关闭所有模拟器
xcrun simctl shutdown 5254D90C-CD43-4214-9E2A-6D662A612116

重置:xcrun simctl erase $UDID

xcrun simctl erase 5254D90C-CD43-4214-9E2A-6D662A612116

需要先关系再重置再启动就看到效果了

6.清理不可用的模拟器

xcrun simctl delete unavailable

7.截图、录屏

截图 xcrun simctl io booted screenshot "<path>"

➜  ~ xcrun simctl io booted screenshot "/Users/wanshanhu79/Desktop/weq/screenImage.png"
Detected file type 'PNG' from extension
Wrote screenshot to: /Users/wanshanhu79/Desktop/weq/screenImage.png

录屏 xcrun simctl io booted recordVideo "<path>"

xcrun simctl io booted recordVideo "/Users/wanshanhu79/Desktop/weq/screenImag.mp4"

进入录屏后,会进入卡顿,按Ctrl+C 会停止录屏。

**如果多个模拟器已经启动,simctl将选择其中的一个。可以用$UDID 替换booted,指定多个模拟器的某个 **

8.安装、卸载应用

安装:build之后得到了.app文件,可以在模拟器中安装

  • xcrun simctl install booted <app路径>
  • xcrun simctl install $UDID <app路径>
➜  ~ xcrun simctl install booted /Users/wanshanhu79/Library/Developer/Xcode/DerivedData/Stdecaux-feozqtjybllbnfcmvopzryhedylt/Build/Products/Debug-iphonesimulator/Stdecaux.app
/// 
➜  ~ xcrun simctl install 6413C54A-B58D-4766-88E4-09217AFE1D1F /Users/wanshanhu79/Library/Developer/Xcode/DerivedData/Stdecaux-feozqtjybllbnfcmvopzryhedylt/Build/Products/Debug-iphonesimulator/Stdecaux.app

卸载:通过bundle identifier来卸载一个应用 xcrun simctl uninstall booted "<bundle identifier>"

xcrun simctl uninstall booted com.logic.stdecaux

9.启动、关闭应用

通过bundle identifier来启动、关闭应用

  • 启动:xcrun simctl launch booted "<bundle identifier>"
  • 关系:xcrun simctl terminate booted "<bundle identifier>"
➜  ~ xcrun simctl launch booted com.logic.stdecaux #启动
com.logic.stdecaux: 56646
➜  ~ xcrun simctl terminate booted com.logic.stdecaux #关闭

11.打开URl

打开网页 xcrun simctl openurl booted "<URL>"

xcrun simctl openurl booted "https://www.sogou.com"

打开app xcrun simctl openurl booted "URLScheme:"

xcrun simctl openurl booted "wx5de298c519d9c4f4:"

12.已安装APP的信息

xcrun simctl appinfo booted "<bundle identifier>"

➜  ~ xcrun simctl appinfo booted "com.logic.stdecaux"
{
    ApplicationType = User;
    Bundle = "file:///Users/wanshanhu79/Library/Developer/CoreSimulator/Devices/3293BD4E-D013-490C-99B7-C4930067EDEA/data/Containers/Bundle/Application/6BC86429-0762-420B-BC9C-01ED1E8AA809/Stdecaux.app";
    BundleContainer = "file:///Users/wanshanhu79/Library/Developer/CoreSimulator/Devices/3293BD4E-D013-490C-99B7-C4930067EDEA/data/Containers/Bundle/Application/6BC86429-0762-420B-BC9C-01ED1E8AA809";
    CFBundleDisplayName = "\U6211\U4eec";
    CFBundleExecutable = Stdecaux;
    CFBundleIdentifier = "com.logic.stdecaux";
    CFBundleName = Stdecaux;
    CFBundleVersion = 2019071403;
    DataContainer = "file:///Users/wanshanhu79/Library/Developer/CoreSimulator/Devices/3293BD4E-D013-490C-99B7-C4930067EDEA/data/Containers/Data/Application/DE9145FC-12B7-4645-B3B9-485251D83172";
    GroupContainers =     {
    };
    Path = "/Users/wanshanhu79/Library/Developer/CoreSimulator/Devices/3293BD4E-D013-490C-99B7-C4930067EDEA/data/Containers/Bundle/Application/6BC86429-0762-420B-BC9C-01ED1E8AA809/Stdecaux.app";
    SBAppTags =     (
    );
}

13.添加图片到模拟器

xcrun simctl addmedia booted "<path>"

xcrun simctl addmedia booted /Users/wanshanhu79/Desktop/weq/screenImage.png

也可以将文件从Finder中拖放到Simulator中的Photos应用中

14.设置模拟器区域设置

模拟器首选项文件包含许多全局设置,包括当前区域设置和语言。~/Library/Developer/CoreSimulator/Devices//data/Library/Preferences/.GlobalPreferences.plist

plutil -p ~/Library/Developer/CoreSimulator/Devices/$UUID/data/Library/Preferences/.GlobalPreferences.plist

~ plutil -p ~/Library/Developer/CoreSimulator/Devices/3293BD4E-D013-490C-99B7-C4930067EDEA/data/Library/Preferences/.GlobalPreferences.plist
{
  "AddingEmojiKeybordHandled" => 1
  "AKLastIDMSEnvironment" => 0
  "AppleITunesStoreItemKinds" => [
    0 => "podcast"
    1 => "artist"
    2 => "itunes-u"
    3 => "booklet"
    4 => "document"
    5 => "movie"
    6 => "eBook"
    7 => "software"
    8 => "software-update"
    9 => "podcast-episode"
  ]
  "AppleKeyboards" => [
    0 => "en_US@sw=QWERTY;hw=Automatic"
    1 => "emoji@sw=Emoji"
    2 => "en_US@sw=QWERTY;hw=Automatic"
  ]
  "AppleKeyboardsExpanded" => 1
  "AppleLanguages" => [
    0 => "en"
  ]
  "AppleLocale" => "en_US"
  "ApplePasscodeKeyboards" => [
    0 => "en_US"
    1 => "emoji"
  ]
  "PKKeychainVersionKey" => 4
}

可以plutil再次使用该命令以编程方式修改首选项。例如,以下shell脚本将当前语言环境和语言更改为日语:

LANGUAGE="ja"
LOCALE="ja_JP"

plutil -replace AppleLocale -string $LOCALE $PLIST
plutil -replace AppleLanguages -json "[ \"$LANGUAGE\" ]" $PLIST

您可以使用相同的技术来调整辅助功能设置(com.apple.Accessibility.plist),例如启用或禁用 Voice Over 和其他辅助技术。

要获取所有可用设置的完整范围,请plutil -p在首选项目录中的所有属性列表上运行。plutil -p ~/Library/Developer/CoreSimulator/Devices/$UUID/data/Library/Preferences/*.plist

相关链接

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

JSmiles

生命进入颠沛而奔忙的本质状态,并将以不断告别和相遇的陈旧方式继续下去。

0 文章
0 评论
84960 人气
更多

推荐作者

遂心如意

文章 0 评论 0

5513090242

文章 0 评论 0

巷雨优美回忆

文章 0 评论 0

junpengz2000

文章 0 评论 0

13郎

文章 0 评论 0

qq_xU4RDg

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文