1. 使用ios-sim
ios-sim是一個可以用命令空着ios模擬器的工具。利用這個命令,我們可以啟動模擬器、安裝app、啟動app、查詢ios sdk,它可以使我們像自動化測試一樣打開xcode,ios-sim只支持xcode6以后的版本。
命令使用如下:
# 安裝ios-sim的命令 # 先安裝node npm install ios-sim -g # 安裝.app包到模擬器 ios-sim launch app文件目錄 --devicetypeid 模擬器版本 ios-sim launch /Users/Desktop/test.app --devicetypeid iPhone-6s #查詢模擬器列表命令 xcrun simctl list
xcode模擬器的位置為:/Users/soumoemoe/Library/Developer/CoreSimulator/Devices
App的位置:
假如模擬器為 iPhone 6s (60B8F826-8241-498A-A180-35C3F4F59562) (Booted)
則application目錄在:/Users/soumoemoe/Library/Developer/CoreSimulator/Devices/60B8F826-8241-498A-A180-35C3F4F59562/data/Containers/Data/Application
2. xcrun:Xcode允許我們使用xcrun命令運行模擬器、管理安裝包
命令使用如下:
# 列出安裝的所有可用模擬器 xcrun instruments -s ''' 結果: iPhone 8 Plus (11.2) [18B8751C-097C-427C-9DB8-BF59FB3C1D7E] (Simulator) iPhone 8 Plus (11.2) + Apple Watch Series 3 - 42mm (4.2) [E381F8A1-54E9-4428-BE4A-7011902C5D69] (Simulator) iPhone SE (11.2) [D8ACFB1F-6678-4014-8993-72050939481D] (Simulator) iPhone X (11.2) [1346D0CB-C0A7-40F9-BB8B-C095B736C696] (Simulator) ''' #開啟指定模擬器 xcrun instruments -w "iPhone 8(11.2) # 安裝指定的app xcrun simctl insall booted <app路徑> # 運行指定的app(com.test.app) xcrun simctl launch booted <app identifier> # 卸載指定的應用 xcrun simctl uninstall booted <app identifier>