首页指南参考教程

为 iOS 模拟器构建

了解如何在使用 EAS Build 时配置和安装 iOS 模拟器的构建。


在 iOS 模拟器上运行应用的构建非常有用。你可以配置构建配置文件并在模拟器上自动安装构建。这提供了一个独立(独立于 Expo Go)版本的应用运行,无需部署到 TestFlight,甚至无需拥有 Apple 开发者账户。

¥Running a build of your app on an iOS Simulator is useful. You can configure the build profile and install the build automatically on the simulator. This provides a standalone (independent of Expo Go) version of the app running without needing to deploy to TestFlight or even having an Apple Developer account.

配置为模拟器构建的配置文件

¥Configuring a profile to build for simulators

要在 iOS 模拟器上安装应用的构建,请修改 eas.json 中的构建配置文件并将 ios.simulator 值设置为 true

¥To install a build of your app on an iOS Simulator, modify the build profile in eas.json and set the ios.simulator value to true:

eas.json
{
  "build": {
    "preview": {
      "ios": {
        "simulator": true
      }
    },
    "production": {}
  }
}

现在,执行如下所示的命令来运行构建:

¥Now, execute the command as shown below to run the build:

Terminal
eas build -p ios --profile preview

请记住,配置文件可以任意命名。在上面的例子中,它被称为 preview。但是,你可以将其称为 localsimulator 或任何最有意义的名称。

¥Remember that a profile can be named whatever you like. In the above example, it is called preview. However, you can call it local, simulator, or whatever makes the most sense.

在模拟器上安装构建

¥Installing build on the simulator

如果你之前尚未安装或运行 iOS 模拟器,请先按照 iOS 模拟器指南 操作,然后再继续。

¥If you haven't installed or run the iOS Simulator before, follow the iOS Simulator guide before proceeding.

构建完成后,CLI 将提示你自动下载并将其安装到 iOS 模拟器上。出现提示时,按 Y 直接安装到模拟器上。

¥Once your build is completed, the CLI will prompt you to automatically download and install it on the iOS Simulator. When prompted, press Y to directly install it on the simulator.

如果你有多个版本,你还可以随时运行 eas build:run 命令来下载特定版本并将其自动安装在 iOS 模拟器上:

¥In case you have multiple builds, you can also run the eas build:run command at any time to download a specific build and automatically install it on the iOS Simulator:

Terminal
eas build:run -p ios

该命令还显示项目的可用构建列表。你可以从此列表中选择要安装在模拟器上的版本。列表中的每个构建都有一个构建 ID、自构建创建以来经过的时间、构建号、版本号和 git 提交信息。如果项目有无效构建,该列表还会显示无效构建。

¥The command also shows a list of available builds of your project. You can select the build to install on the simulator from this list. Each build in the list has a build ID, the time elapsed since the build creation, the build number, the version number, and the git commit information. The list also displays invalid builds if a project has any.

例如,下图列出了项目的两个先前版本:

¥For example, the image below lists two previous builds of a project:

构建安装完成后,它将出现在主屏幕上。如果是开发版本,请打开终端窗口并通过运行命令 npx expo start 启动开发服务器。

¥When the build's installation is complete, it will appear on the home screen. If it's a development build, open a terminal window and start the development server by running the command npx expo start.

运行最新版本

¥Running the latest build

--latest 标志传递给 eas build:run 命令以在 iOS 模拟器上下载并安装最新版本:

¥Pass the --latest flag to the eas build:run command to download and install the latest build on the iOS Simulator:

Terminal
eas build:run -p ios --latest
Expo 中文网 - 粤ICP备13048890号