xcodebuild
首先使用xcodebuild命令打出.app,默認(rèn)工程已經(jīng)配置好了scheme
xcodebuild -scheme CTRIPWireLess -workspace CTRIPWireLess.xcodeproj/project.workspace -destination '"platform=iOS Simulator,iPhone 6" -derivedDataPath ./tmp
參數(shù)解釋:
-scheme : xcode中配置的scheme,用來生成一個product的過程
-workspace:使用-scheme就必須使用-workspace指定
-destination:product要安裝到的device類型,上文我們指定的是iPhone 6的模擬器,所以最終.app也只能安裝到iPhone 6模擬器中
-derivedDataPath:build過程中的生成中間文件的指定目錄卵皂,./tmp說明是在當(dāng)前目錄下新建tmp存儲中間文件,最終.app也在該目錄的子目錄中
上述命令執(zhí)行成功后砚亭,終端會出現(xiàn)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]"
上述命令執(zhí)行完畢灯变,就能看到iPhone 6模擬器啟動成功
xcrun simctl
現(xiàn)在需要安裝xcodebuild生成的.app到iPhone 6模擬器中
xcrun simctl install booted ./tmp/Build/Product/Debug-iphoneSimulator/CTRIPWireless.app
命令執(zhí)行成功后,會看到模擬器刷新了一下
這時候捅膘,可以滑動模擬器查找剛剛安裝的APP添祸,手動點開APP。
當(dāng)然寻仗,我絕對會告訴你一種高逼格的啟動方式:
通過bundleIdentifier啟動APP
xcrun simctl launch booted 'com.tczhu.myapp'
命令執(zhí)行成功后刃泌,app會自己啟動
更多擴展:
刪除模擬器上安裝的APP
xcrun simctl uninstall booted 'com.tczhu.myapp'