我可以使用Xcode命令行工具构建,有没有办法能够使用它们来运行应用程序?(例如,相当于在Xcode中按下Cmd+R)
open -a Simulator.app
首先决定要使用哪个设备:
xcrun simctl list
这将给你一个设备列表:
-- iOS 9.0 --
iPhone 4s (56632E02-650E-4C24-AAF4-5557FB1B8EB2) (Shutdown)
iPhone 5 (ACD4DB7B-9FC9-49D5-B06B-BA5D5E2F5165) (Shutdown)
iPhone 5s (A8358B76-AD67-4571-9EB7-FFF4D0AC029E) (Shutdown)
iPhone 6 (1D46E980-C127-4814-A1E2-5BE47F6A15ED) (Shutdown)
iPhone 6 Plus (FD9F726E-453A-4A4C-9460-A6C332AB140B) (Shutdown)
选择你想要的ID(例如FD9F726E-453A-4A4C-9460-A6C332AB140B),如果需要,可以使用xcrun simctl create
创建自己的设备。
使用该设备启动模拟器(用ID替换YOUR-DEVICE-ID)
/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator -CurrentDeviceUDID <YOUR-DEVICE-ID>
现在您应该可以使用simctl安装和启动命令。
xcrun simctl install <YOUR-DEVICE-ID> <PATH-TO-APPLICATION-BUNDLE>
xcrun simctl launch <YOUR-DEVICE-ID> <BUNDLE-ID-OF-APP-BUNDLE>
xcrun simctl help
获取更多详细信息。请注意,使用simctl启动设备目前(Xcode 7.2)不能让您执行其他与该设备相关的操作,例如启动或安装应用程序。要实际执行任何有趣的操作,您需要在模拟器中启动设备。此外,您无法删除正在模拟器中使用的设备,因此在尝试删除任何内容之前,您必须退出/关闭模拟器。
/Users/username/Library/Developer/Xcode/DerivedData/YourApp-cuozdynseabctdefrjsejhldxden/Build/Products/Debug-iphonesimulator
- kosiara - Bartosz Kosarzyckiopen -a Simulator --args -CurrentDeviceUDID <YOUR-DEVICE-ID>
这个命令也可以用于启动模拟器。 - sgdesmetopen -a simulator
它对我起作用了
"simulator" != "Simulator.app" // true
-> @MAhipalSingh "模拟器" != "Simulator.app" // 真"
- ICW这是您要寻找的答案:
打开终端
xcrun simctl list
获取您想要启动的设备的 UDID
将其粘贴到终端中
open -a Simulator --args -CurrentDeviceUDID 0566AC33-9B91-2DR2-B5BB-C916D3BA8MD3
打开您的终端并粘贴此代码:
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app
使用xcrun simctl list
获取模拟器及其UDID列表。
然后使用xcrun simctl boot <UDIDs>
打开特定的模拟器。
open -a Simulator
命令。 - friederbluemleopen /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/
Xcode命令行工具
。例如:xcodebuild test -scheme MyiOSApp -destination 'platform=iOS,name=iPod touch'
@AlexChesters - Llogari Casas最佳解决方案之一:
xcrun simctl boot $(xcrun simctl list devices | grep -m 1 'iPhone 12 Pro' |grep -E -o -i '([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})')
总结
open -a Simulator && xcrun simctl boot 'iPhone 8 Plus'
这里有一个方便的命令,可以构建项目并在终端中运行它:
xcodebuild -scheme <scheme_name> -destination <destination_name> build && xcrun simctl launch booted <bundle_identifier>
<scheme_name>
- 特定模式的名称,例如 "MyApp (开发环境)"
<destination_name>
- 要运行的模拟器的名称。例如 "name=iPhone 14 Pro"
<bundle_identifier>
- 您项目的包标识符。示例: com.johnne.myapp
执行结果: