是否有通过命令行启动iOS模拟器的简单方法?我在一个项目中工作,使用grep获取模拟器的UUID,然后通过UUID启动它有些复杂:
UUID=$(
xcrun instruments -s |
grep "${{ matrix.device }}" | # Grep device(s) - can expect more than one
grep -Eo -m1 "[.*]" | # Extract device ID of the first result
sed -e 's/^[//' -e 's/]$//' # Trimming the square brackets surrounding UUID
)
xcrun simctl boot "$UUID"
获取设备名称列表:
运行xcrun simctl list devices
,输出:
== Devices ==
-- iOS 14.5 --
-- iOS 14.5 --
iPhone 8 (FA86F02A-B7AF-412B-996C-7B086025A73C) (Shutdown)
iPhone 8 Plus (F9FB94EA-3EFE-497E-A994-7C112CD65462) (Shutdown)
iPhone 11 (C14D6993-CA37-4E50-86C9-0D2827B35D48) (Shutdown)
iPhone 11 Pro (4E137620-962B-4756-B913-2EE9AF99D3D6) (Shutdown)
iPhone 11 Pro Max (935DA14A-A4AB-4EC0-8AFB-103ABF2C6608) (Shutdown)
iPhone SE (2nd generation) (1C78EEFC-293D-4EBD-8F4C-9FACEB842631) (Shutdown)
iPhone 12 mini (A4ED4EF6-8F84-452F-927D-40BA30D6CF62) (Booted)
iPhone 12 (92F57737-CB75-4A99-84BB-E221F156B578) (Booted)
iPhone 12 Pro (C62C81AB-18C7-4DAD-9023-AD4E1A64140F) (Shutdown)
iPhone 12 Pro Max (BF1967DF-A0A7-4740-961F-DCBEB4CAFF60) (Shutdown)
iPod touch (7th generation) (47DFA553-1955-49BA-A4D3-CE7C397282AC) (Shutdown)
iPad Pro (9.7-inch) (0E84438C-2369-4D26-ABBE-BC0B71E76839) (Shutdown)
iPad (8th generation) (C7ABF216-2256-4715-9FAB-F83EA595ECEB) (Shutdown)
iPad Air (4th generation) (E7B4E2E7-88F6-4133-ACE5-7B8B19E96F43) (Shutdown)
iPad Pro (11-inch) (3rd generation) (9793FE60-0749-49D8-8ACE-4B46C1B4901B) (Shutdown)
iPad Pro (12.9-inch) (5th generation) (8755F8FE-EDCB-4603-B0D0-262A83DC723A) (Shutdown)
-- tvOS 14.5 --
Apple TV (3FEF7ABC-4CED-4473-9B76-63C19707B28C) (Shutdown)
Apple TV 4K (2nd generation) (200C414D-4699-4F3A-8E28-0DC6D598E557) (Shutdown)
Apple TV 4K (at 1080p) (2nd generation) (7363F807-A22F-49B2-917A-F248002EABDB) (Shutdown)
-- watchOS 7.4 --
Apple Watch Series 5 - 40mm (71BD5079-1D90-421F-925C-4D9F288F7535) (Shutdown)
Apple Watch Series 5 - 44mm (3F587446-DC30-4C5D-A101-0D6D53B3E71F) (Shutdown)
Apple Watch Series 6 - 40mm (CAE878C0-9DD5-4E74-9BE9-2262819BA43D) (Shutdown)
Apple Watch Series 6 - 44mm (000CCEE8-E41B-4D52-B755-69B37D2BBC5E) (Shutdown)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-15-0 --
iPad (9th generation) (B2819113-C651-47F8-9ABF-38FBB530927A) (Shutdown) (unavailable, runtime profile not found)
iPad mini (6th generation) (B2D49664-1582-4A37-918B-53EA0ADAA898) (Shutdown) (unavailable, runtime profile not found)
iPhone 13 (43F7E023-6AEF-4ED0-8FCC-E88303DE3B70) (Shutdown) (unavailable, runtime profile not found)
iPhone 13 Pro (1C2C397B-9774-459A-B4F1-81CDE52D0246) (Shutdown) (unavailable, runtime profile not found)
iPhone 13 Pro Max (0BCB5E9B-A527-46FA-B952-9F3629AF84D5) (Shutdown) (unavailable, runtime profile not found)
iPhone 13 mini (00CBE649-0FD7-49EF-AE95-53DAAE3DDCBE) (Shutdown) (unavailable, runtime profile not found)
-- Unavailable: com.apple.CoreSimulator.SimRuntime.watchOS-8-0 --
Apple Watch Series 7 - 41mm (DAC19B17-E885-4B21-B1B3-85969EE0E693) (Shutdown) (unavailable, runtime profile not found)
Apple Watch Series 7 - 45mm (F73EAA78-5B3E-4E9D-8643-1EFC1CF1F990) (Shutdown) (unavailable, runtime profile not found)
然后,按设备名称启动:
xcrun simctl boot "iPhone 12"
注意:在CI/CD中,您可以使用设备变量或矩阵在多个设备上运行,例如xcrun simctl boot "${{ matrix.device }}"
。
启动应用程序
执行xcrun simctl launch "iPhone 12" com.example.app-name
命令。您可以通过运行xcrun simctl list devices | grep "iPhone 12"
来检查设备是否启动。
查看UI
直接打开Simulator.app