iOS安装app到Simulator

命令行安装.app包到Simulator(不能直接装.ipa的包)。

查看模拟器列表:

1
instruments -s devices

启动模拟器:

1
xcrun instruments -w 'iPhone 7'

若遇到如下错误:

Instruments Usage Error: Ambiguous device name/identifier ‘iPhone 7’:
iPhone 7 (10.3.1) [BAACF4D1-9405-4E6F-9B2F-2958CAA82745]
iPhone 7 Plus (10.3.1) [BCA2A32C-EE02-4DB3-B4E7-814583AE60B2]
iPhone 7 Plus (10.3.1) + Apple Watch Series 2 - 42mm (3.2) [1D7FF757-387C-47F1-9565-DD4C5D911AEB]
iPhone 7 (10.3.1) + Apple Watch Series 2 - 38mm (3.2) [6FA79326-DB3A-42FE-B387-2697C4925057]

可以直接用udid启动,xcrun instruments -w 'BAACF4D1-9405-4E6F-9B2F-2958CAA82745'

安装目标app

这里不能直接装.ipa的包,只能装.app包,可以在xcode工程的Products下找到。注意必须是simulator下的app包(真机对应app包是基于arm的,装到电脑模拟器打开会闪退)。

1
xcrun simctl install booted /PathToTheApp/test.app

(当然有源码时xcode直接运行一下项目也能自动安装。)

卸载app

1
xcrun simctl uninstall booted com.xxx.here-is-bundle-id

open a webpage in safari

1
xcrun simctl openurl <Device UDID> http://www.tracenote.com

查看已启动的模拟器

1
xcrun simctl list|grep Booted