This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

iOS 模拟器

了解如何在 Mac 上安装 iOS 模拟器并使用它来开发应用。


直接在电脑上开发应用可能比不断与 iPhone 或 iPad 互动更方便,尤其是在网络状况较慢时,或由于局域网限制需要隧道连接时。

🌐 Developing your app directly on a computer can be more convenient than constantly interacting with an iPhone or iPad, especially when network conditions are slow or when a tunnel connection is required due to LAN limitations.

本指南说明了如何在 Mac 上安装 iOS 模拟器以进行应用开发。请注意,iOS 模拟器只能安装在 macOS 上。如果你在 Windows 或 Linux 机器上开发 iOS 应用,你需要一台真正的 iOS 设备或 EAS 模拟器。

🌐 This guide explains how to install the iOS Simulator on your Mac for app development. Note that the iOS Simulator can only be installed on macOS. If you are developing an iOS app from a Windows or a Linux machine, you need a physical iOS device or EAS Simulator.

设置 Xcode 和 Watchman

🌐 Setup Xcode and Watchman

1

安装 Xcode

🌐 Install Xcode

打开 Mac 应用商店,搜索 Xcode,然后点击 安装(如果已经安装则点击 更新)。

🌐 Open up the Mac App Store, search for Xcode, and click Install (or Update if you have it already).

2

安装 Xcode 命令行工具

🌐 Install Xcode Command Line Tools

打开 Xcode,从 Xcode 菜单中选择 设置...(或按 cmd ⌘ + ,)。在侧边栏选择 位置,然后在 命令行工具 下拉菜单中选择最新版本来安装工具。

3

在 Xcode 中安装 iOS 模拟器

🌐 Install an iOS Simulator in Xcode

要安装 iOS 模拟器,请打开 Xcode > 设置... > 组件,在 平台支持 > iOS ... 下,点击 获取。

🌐 To install an iOS Simulator, open Xcode > Settings... > Components, and under Platform Support > iOS ..., click Get.

4

安装 Watchman

🌐 Install Watchman

Watchman 是一个用于监控文件系统变化的工具。安装它将带来更好的性能。你可以通过以下方式安装它:

Terminal
- brew update
- brew install watchman

4

试试

🌐 Try it out

使用 npx expo start 运行你的应用,然后从命令行按 I 。

你可能会收到一个关于需要接受 Xcode 许可的警告。运行它建议的命令。再次打开你的应用看看是否成功。如果没有,请查看下面的故障排除提示。

🌐 You may get a warning about needing to accept the Xcode license. Run the command that it suggests. Open your app again to see if it was successful. If not, check the troubleshooting tips below.

你也可以在 Expo CLI 中按 Shift + I 以交互方式选择要打开的模拟器。

Expo 轨道

🌐 Expo Orbit

你可以使用 Expo Orbit 应用,它允许你在 macOS 的菜单栏上一键启动构建和模拟器管理。

🌐 You can use the Expo Orbit app which allows launching builds and simulator management with one click from the menu bar on macOS.

使用 Expo 轨道

了解更多关于如何使用 Expo Orbit 的信息。

局限性

🌐 Limitations

虽然 iOS 模拟器对于快速开发非常有用,但它确实存在一些限制。下面我们将列出一些影响 Expo API 的主要区别。不过,更多详情请参阅 Apple 的文档。

🌐 Although the iOS Simulator is great for rapid development, it does come with a few limitations. We'll list out a few of the main differences that affect Expo APIs below. However, see Apple's documentation for more details.

模拟器中以下硬件不可用:

🌐 The following hardware is unavailable in the Simulator:

  • 音频输入
  • 晴雨表
  • 相机
  • 运动支持(加速度计和陀螺仪)

模拟器还会在 iOS 11 及更高版本上暂停后台应用和进程。

🌐 The Simulator also suspends background apps and processes on iOS 11 and later.

故障排除

🌐 Troubleshooting

打开模拟器时,CLI似乎卡住了

🌐 The CLI seems to be stuck when opening a Simulator

有时候 iOS 模拟器对 open 命令没有反应。如果它似乎卡在这个提示上,自己先启动一个模拟器,然后再运行你的应用。

🌐 Sometimes the iOS Simulator doesn't respond to the open command. If it seems stuck on this prompt, start a simulator yourself, then run your app again.

Terminal
# List the simulators installed on your Mac
- xcrun simctl list devices available

# Start one of them by name
- xcrun simctl boot "iPhone 17"

Xcode 27 用 Device Hub 替代了模拟器应用。运行 open -a DeviceHub 来打开它。每个正在运行的设备都会显示在侧边栏。在 Xcode 26 上,则运行 open -a Simulator。

🌐 Xcode 27 replaces the Simulator app with Device Hub. Run open -a DeviceHub to open it. Each running device appears in the sidebar. On Xcode 26, run open -a Simulator instead.

你可以同时运行多个模拟器。Expo CLI 总是会针对最近打开的模拟器。

🌐 You can run more than one simulator at the same time. Expo CLI always targets the most recently opened simulator.

模拟器已打开,但 Expo Go 应用无法在其中启动

🌐 Simulator opened but the Expo Go app isn't opening inside of it

第一次在模拟器中安装应用时,iOS 会询问你是否想打开 Expo Go 应用。你可能需要与模拟器进行一些操作(点击、拖动某些东西)以显示此提示,然后按 确定。

🌐 The first time you install the app in the simulator, iOS will ask if you'd like to open the Expo Go app. You may need to interact with the simulator (click around, drag something) for this prompt to show up, then press OK.

我如何安装特定版本的 Expo Go?

🌐 How do I install a specific version of Expo Go?

你可以创建一个具有所需 SDK 版本的项目,并在模拟器中打开它以安装匹配版本的 Expo Go。

🌐 You can create a project with the desired SDK version and open it in a simulator to install the matching version of Expo Go.

Terminal
# Bootstrap an SDK 57 project
- npx create-expo-app --template blank@57

# Open the app on a simulator to install the required Expo Go app
- npx expo start --ios
# Bootstrap an SDK 57 project
- yarn create expo-app --template blank@57

# Open the app on a simulator to install the required Expo Go app
- yarn expo start --ios
# Bootstrap an SDK 57 project
- pnpm create expo-app --template blank@57

# Open the app on a simulator to install the required Expo Go app
- pnpm expo start --ios
# Bootstrap an SDK 57 project
- bun create expo --template blank@57

# Open the app on a simulator to install the required Expo Go app
- bun expo start --ios

或者,你可以通过 expo-go CLI 传递 SDK 版本来下载特定版本的 Expo Go,或者使用 latest 获取最新的 SDK 版本。此命令会将 Expo Go 应用下载到当前目录,并缓存到 ~/.expo 下。

🌐 Alternatively, you can download a specific version of Expo Go with the expo-go CLI by passing an SDK version, or use latest for the latest SDK version. This command downloads the Expo Go app to the current directory and caches it under ~/.expo.

Terminal
- npx expo-go download ios latest
- yarn dlx expo-go download ios latest
- pnpm dlx expo-go download ios latest
- bunx expo-go download ios latest

Expo CLI 正在打印关于 xcrun 的错误信息,我该怎么办?

🌐 Expo CLI is printing an error message about xcrun, what do I do?

对于各种错误,请尝试以下方法:

🌐 For miscellaneous errors, try the following:

  • 在模拟器上手动卸载 Expo Go,然后通过在 Expo CLI 终端界面中按 Shift + I 并选择所需的模拟器来重新安装。
  • 如果这没用,可以在设备中心选择模拟器,然后选择 设备 > 重置内容和设置...
    在 Xcode 26 的模拟器应用中,这个菜单项叫做 抹掉所有内容和设置...
    这会用一个空白镜像重新初始化你的模拟器。有时候当你的电脑内存不足,模拟器无法保存一些内部文件导致设备处于损坏状态时,这个操作会很有用。