如何从终端启动 iOS 模拟器?

How can I launch the iOS Simulator from Terminal?

我可以使用 Xcode 命令行工具进行构建,有什么方法可以让我真正 运行 使用它们来构建应用程序吗? (例如相当于在 Xcode 中按 Cmd+R)

open /Applications/Xcode.app/Contents/Developer/Applications/iOS\ Simulator.app/

打开您的终端并粘贴此代码:

open /Applications/Xcode.app/Contents/Developer/Applications/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) 不允许您对该设备执行任何其他操作,例如启动或安装应用程序。您需要在模拟器中启动设备才能实际执行任何有趣的操作。此外,您无法删除模拟器正在使用的设备,因此在尝试删除任何内容之前,您必须 quit/kill 模拟器。

在终端中输入: open -a Simulator.app

open -a simulator 

对我有用

这就是您要找的答案:

  1. 打开终端

  2. xcrun simctl list

  3. 获取要启动的设备的标识符

  4. 将此粘贴到终端

  5. open -a Simulator --args -CurrentDeviceUDID 0566AC33-9B91-2DR2-B5BB-C916D3BA8MD3

#更新 在新的 Xcode 更新中,支持的模拟器从 iPhone 8 开始

从这个日期(2022)开始,它会起作用:

open -a simulator 

这是最简单的方法。

使用 xcrun simctl list 获取模拟器列表及其 UDID。 然后使用 xcrun simctl boot <UDIDs>

打开一个特定的模拟器