iOS-通过命令行安装.app到模拟器

xcodebuild

首先使用xcodebuild命令打出.app,默认工程已经配置好了scheme

  xcodebuild -scheme CTRIPWireLess -workspace CTRIPWireLess.xcodeproj/project.workspace -destination '"platform=iOS Simulator,iPhone 6" -derivedDataPath ./tmp 

参数解释:
-scheme : xcode中配置的scheme,用来生成一个product的过程
-workspace:使用-scheme就必须使用-workspace指定
-destination:product要安装到的device类型,上文我们指定的是iPhone 6的模拟器,所以最终.app也只能安装到iPhone 6模拟器中
-derivedDataPath:build过程中的生成中间文件的指定目录,./tmp说明是在当前目录下新建tmp存储中间文件,最终.app也在该目录的子目录中

上述命令执行成功后,终端会出现build success,同时tmp目录的子目录中会有.app

xcrun instruments

首先找到iPhone 6模拟器的identifier

 instruments -s 

终端输出:

Apple TV 1080p (10.1) [23602114-547F-41D9-8CBC-C290DC2A9CDA] (Simulator)
Apple Watch - 38mm (3.1) [AB2CB46D-F75B-499E-99C6-FC6DD9DB5A13] (Simulator)
Apple Watch - 42mm (3.1) [48EA6948-69BE-4D14-BC89-26629CB323E2] (Simulator)
iPad Air (10.2) [16997D62-B573-46E0-B380-74D423690842] (Simulator)
iPad Air 2 (10.2) [B1B8727E-6EAF-4C62-AE87-D8ECF0D50B01] (Simulator)
iPad Pro (12.9 inch) (10.2) [3B15C25A-516E-4059-9DCF-B64FA894831F] (Simulator)
iPad Pro (9.7 inch) (10.2) [900E15F9-50CA-4AAF-B673-EAEF5282EB41] (Simulator)
iPad Retina (10.2) [EC060017-FAD5-4E57-A605-41710FD9263A] (Simulator)
iPhone 5 (10.2) [C0D39560-72C9-48B4-AB39-0A3CC7BF0207] (Simulator)
iPhone 5s (10.2) [B977F2D1-5582-406B-9EB5-FE886428D02A] (Simulator)
iPhone 6 (10.2) [922B0587-0B93-47D4-9287-C3EDA3A63A01] (Simulator)
iPhone 6 Plus (10.2) [EDA07D6A-AA7D-476F-8A1A-69A8492B149F] (Simulator)
iPhone 6s (10.2) [DA919449-73B4-40CE-9778-E680B74054A4] (Simulator)
iPhone 6s Plus (10.2) [3207D39A-8F66-4418-ADF6-6FB486EAB538] (Simulator)
iPhone 7 (10.2) [200B165D-3C06-4ABD-BA1E-1525EE7EF9C7] (Simulator)
iPhone 7 (10.2) + Apple Watch Series 2 - 38mm (3.1) [8ED921AF-27E2-4C4F-8BD2-3C8B0A92344F] (Simulator)
iPhone 7 Plus (10.2) [C2230E69-E1CE-4D37-ACAC-BFAE92C1F63C] (Simulator)
iPhone 7 Plus (10.2) + Apple Watch Series 2 - 42mm (3.1) [1EE6A538-C01E-4AEE-9498-9CE7F7778632] (Simulator)
iPhone SE (10.2) [7A70FBC7-EBA2-480B-9246-BEDE841E5157] (Simulator)
Known Templates:
...

找出iPhone 6模拟器
iPhone 6 (10.2) [922B0587-0B93-47D4-9287-C3EDA3A63A01]

启动iPhone 6模拟器

xcrun instruments -w "iPhone 6 (10.2) [922B0587-0B93-47D4-9287-C3EDA3A63A01]"

上述命令执行完毕,就能看到iPhone 6模拟器启动成功

xcrun simctl

现在需要安装xcodebuild生成的.app到iPhone 6模拟器中

xcrun simctl install booted ./tmp/Build/Product/Debug-iphoneSimulator/CTRIPWireless.app

命令执行成功后,会看到模拟器刷新了一下
这时候,可以滑动模拟器查找刚刚安装的APP,手动点开APP。
当然,我绝对会告诉你一种高逼格的启动方式:
通过bundleIdentifier启动APP

 xcrun simctl launch booted 'com.tczhu.myapp'

命令执行成功后,app会自己启动

更多扩展:
删除模拟器上安装的APP

xcrun simctl uninstall booted 'com.tczhu.myapp'

你可能感兴趣的:(iOS-通过命令行安装.app到模拟器)