最近由于公司需要定时启动app上传一定数据,所以每天都要点击启动app,很容易就忘了,因此需要定时启动app。
准备工作:
- 确保模拟器进程活着;
- 安装的.app文件,使用对应模拟器进行编译;
- 使用命令对iOS app模拟器操作,可参考:xcrun simctl --help
基础知识
- 启动模拟器
xcrun instruments -w '模拟器型号'
如: xcrun instruments -w 'iPhone 8 (11.2) [9E1FB925-C3CF-4EA5-972E-82C6F90B9993]'
一般一个模拟器都会有许多模拟器,包括iWatch、iPhone、iPad等,可通过以下命令列出当前所安装的所有型号:
000000-C:~ 00000$ instruments -s
。。。
iPhone 6s (11.2) [AE40A597-0C22-47D2-96C6-B2BC76D3FE8E] (Simulator)
iPhone 6s (9.0) [C9791334-4DBB-4E82-A533-8C1D21AE770E] (Simulator)
iPhone 6s Plus (10.1) [F3900203-B70F-4BF4-9CA5-06D5396BC132] (Simulator)
iPhone 6s Plus (10.3.1) [89C97F5B-F71F-4973-BC3D-A46BF80F9D78] (Simulator)
iPhone 6s Plus (11.2) [AED4149C-CE02-4BA8-B2D4-2B3A383A162A] (Simulator)
iPhone 6s Plus (9.0) [E54A2B5D-BE42-4979-8FDC-508DBCE78AF6] (Simulator)
iPhone 7 (10.1) [8ACA26C1-AD70-4FA8-B37F-58044AE95EB1] (Simulator)
iPhone 7 (10.3.1) [33F29703-D187-4639-ACF8-F0ED17D88A4A] (Simulator)
iPhone 7 (11.2) [79F6D889-A93B-4F80-90C0-D56371C15D4F] (Simulator)
。。。
或
xcrun simctl boot '模拟器UDID'
如:xcrun simctl boot 'F1FCFDD1-8691-411D-8C96-B38BB13EB551'
- 安装app
Usage: xcrun simctl install <device> <path>
注:path路径是后缀为.app的文件路径,此文件在自己工程中编译完成后即可得到,在左侧目录树Products中,右击找到xxx.app文件
如:xcrun simctl install 'F1FCFDD1-8691-411D-8C96-B38BB13EB551' '/Users/analysyseguan/Desktop/千帆对数/工程文件/EGMonitor_SDK_Demo.app'
- 启动某个app
Usage: xcrun simctl launch <device> <app identifier>
xcrun simctl launch 'F1FCFDD1-8691-411D-8C96-B38BB13EB551' 'com.analysys.FanzhouLocalized'
- 关闭某个app
Usage: simctl terminate <device> <app identifier>
xcrun simctl terminate 'F1FCFDD1-8691-411D-8C96-B38BB13EB551' 'com.analysys.FanzhouLocalized'
- 卸载app
Usage: simctl uninstall <device> <app identifier>
xcrun simctl uninstall 'F1FCFDD1-8691-411D-8C96-B38BB13EB551' 'com.analysys.FanzhouLocalized'
注:以上<device>均可使用booted替代,booted代表当前选中的模拟器;