为 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:
{ "build": { "preview": { "ios": { "simulator": true } }, "production": {} } }
现在,执行如下所示的命令来运行构建:
🌐 Now, execute the command as shown below to run the build:
- eas build -p ios --profile preview请记住,配置文件可以命名为你喜欢的任何名字。在上面的例子中,它被称为 preview。不过,你可以称它为 local、simulator,或者任何最合理的名字。
🌐 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 模拟器指南。
一旦构建完成,CLI 会提示你自动下载并安装到 iOS 模拟器上。出现提示时,按 Y 可以直接将其安装到模拟器上。
如果你有多个版本,你也可以随时运行 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:
- 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:
- eas build:run -p ios --latest