iOS模拟器命令
简介
可用通过xcrun simctl 和ios-sim来查看和管理iOS模拟器
xcrun simctl是Xcode自带的,ios-sim可用通过以下指令安装
npm install ios-sim -g
1. 查看已安装的设备
xcrun instruments -s
运行结果
iPhone 5s (12.1) [7546EE13-F9C4-4708-BDB3-C9DA78FF33DD] (Simulator) iPhone 6 (12.1) [9753C425-D150-4D8E-92B5-3B053A9DDAEF] (Simulator) iPhone 6 Plus (12.1) [8215B4DC-6AC4-44AC-AE31-2B23879FF87B] (Simulator) iPhone 6s (12.1) [0AD82922-9357-47D5-815D-B82A6CF9C8FC] (Simulator) iPhone 6s Plus (12.1) [9B94F04B-6FF5-488A-960A-81D85EEC157F] (Simulator) iPhone 7 (12.1) [E66A26DD-2063-4FBE-9AE8-9E82C4A251FF] (Simulator) iPhone 7 Plus (12.1) [961F78AE-8D21-40B5-B228-A9DE1DABC61E] (Simulator)
其中iPhone xx (xx) 为设备名称, 后面的一串编号为UDID
2. 查看设备状态
xcrun simctl list
运行结果:
iPhone 5s (7546EE13-F9C4-4708-BDB3-C9DA78FF33DD) (Shutdown) iPhone 6 (9753C425-D150-4D8E-92B5-3B053A9DDAEF) (Shutdown) iPhone 6 Plus (8215B4DC-6AC4-44AC-AE31-2B23879FF87B) (Shutdown) iPhone 6s (0AD82922-9357-47D5-815D-B82A6CF9C8FC) (Shutdown) iPhone 6s Plus (9B94F04B-6FF5-488A-960A-81D85EEC157F) (Shutdown) iPhone 7 (E66A26DD-2063-4FBE-9AE8-9E82C4A251FF) (Shutdown) iPhone 7 Plus (961F78AE-8D21-40B5-B228-A9DE1DABC61E) (Shutdown)
最后的shotdown标识状态是关机状态
3. 启动指定设备名称的模拟器
xcrun instruments -w "iPhone 7 (12.1)"
4. 启动指定udid的模拟器
xcrun simctl boot E66A26DD-2063-4FBE-9AE8-9E82C4A251FF
执行boot后,如果遇到模拟器没有打开可以再执行以下指令, 像下面这样
xcrun simctl boot "E66A26DD-2063-4FBE-9AE8-9E82C4A251FF" open "/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/"
5. 关闭指定udid的模拟器
xcrun simctl shutdown E66A26DD-2063-4FBE-9AE8-9E82C4A251FF
6. 关闭所有打开的模拟器
xcrun simctl shutdown all
7.重置模拟器(清除模拟器的数据和设置)
xcrun simctl erase E66A26DD-2063-4FBE-9AE8-9E82C4A251FF
注意重置前需求先关闭模拟器
8. 安装指定的app
xcrun simctl install <uuid> <app路径>
注意模拟器不支持直接安装ipa, 需要将ipa解压出来使用xxx.app文件进行安装
如果只有一个设备时可以使用指令
xcrun simctl install booted <app路径>
9.启动指定的app
xcrun simctl launch <device> <bundle identifier>
如果只有一个设备时可以使用指令
xcrun simctl launch booted <bundle identifier>