为 iOS 设备创建并运行云构建

了解如何使用 EAS Build 配置 iOS 设备的开发版本。


在本章中,我们将使用 EAS Build 创建一个可以在 iOS 设备上运行的开发版本。

🌐 In this chapter, we'll create a development build that can run on an iOS device with EAS Build.

iOS 设备的开发版本以 .ipa 格式生成,这是 iOS 应用安装的标准格式。

🌐 Development builds for iOS devices are generated in the .ipa format, which is standard for iOS app installations.

观看:为 iOS 实体设备创建开发构建
观看:为 iOS 实体设备创建开发构建

先决条件

🌐 Prerequisites

在我们开始之前,请确保你拥有:

🌐 Before we begin, ensure you have:

  • 苹果开发者账户: 访问必要的凭证需要此账户,用于签名我们的应用,因为每个构建都需要签名以验证应用来自可信来源。EAS Build 可以帮助管理这些凭证。
  • 在 iOS 16 及更高版本上已启用开发者模式: 要在设备上安装开发版本,需要启用开发者模式。如果这是你第一次操作,或者当前已被禁用,请参阅这些说明以启用开发者模式

配置文件

🌐 Provisioning profile

要在 iOS 设备上启动开发,我们必须:

🌐 To initiate development on an iOS device, we have to:

  • 通过创建新的配置文件来注册设备。
  • 下载此配置文件并将其安装到设备上。

1

注册 iOS 设备

🌐 Register an iOS device

使用 EAS CLI,运行命令以注册新的 Apple 设备:

🌐 With EAS CLI, run the command to register a new Apple device:

Terminal
eas device:create

该命令提示我们以下问题:

🌐 This command prompts us with the following questions:

  • 你现在在项目目录中。你想使用 your-account-name 账户吗?Y
  • Apple ID。 在此步骤中,输入你的 Apple ID。然后它将登录我们的 Apple Developer 账户。请按照终端窗口中的步骤操作。
  • 你想如何注册你的设备? 选择 网站,它会生成一个可以在 iOS 设备上打开的注册网址。

信息 提示:如果你或你的团队有多台设备,可以将配置描述文件链接共享给这些设备,以便下载和安装该配置文件。

2

下载并安装配置文件

🌐 Download and install profile

在设备的网页浏览器中,打开上一步提供的链接,然后点击 下载配置文件按钮

🌐 On a device's web browser, open the link provided in the previous step and tap the Download Profile button.

打开 设置 应用,这会提示我们注册设备。

🌐 Open the Settings app, which prompts us to register our device.

点击 安装 来注册 iOS 设备。

🌐 Tap Install to register the iOS device.

安装配置文件后,我们的设备会将我们重定向回网页浏览器,并显示一个成功消息,表明该过程已完成。

🌐 After the provisioning profile is installed, our device redirects us back to the web browser, displaying a success message indicating the completion of the process.

适用于 iOS 设备的开发构建

🌐 Development build for iOS device

1

创建

🌐 Create

要在 iOS 设备上创建开发构建,请确保在 build.development 配置文件下:

🌐 To create a development build on an iOS device, make sure that under the build.development profile:

  • developmentClienteas.json 中被设置为 true,这是由默认配置完成的。
  • 然后,使用 ios 作为平台,development 作为构建配置运行 eas build 命令:
Terminal
eas build --platform ios --profile development

信息 提示:下次运行 eas build 命令时,你也可以使用 -p 来指定平台。它是 --platform 的缩写。

在我们第一次创建构建时,该命令会向我们提出以下问题:

🌐 This command prompts us with the following questions when we create the build for the first time:

  • 你希望你的 iOS 包标识符是什么?回车 选择此提示提供的默认值。如果尚未定义,这将在 app.json 中添加 ios.bundleIdentifier
  • 你想登录你的 Apple 账户吗? 由于我们是第一次创建开发版,它将要求我们 生成一个新的 Apple 分发证书。两次都按 Y
  • 选择用于临时构建的设备。这是关键部分,这也是为什么我们之前必须注册配置文件。我们可以在这里选择一个或所有已注册的设备,然后按回车键以在这些设备上安装该构建。

信息 仅当你跳过了iOS 模拟器章节时: 你将会看到提示 iOS 应用仅使用标准/豁免加密?Y 以选择该提示提供的默认值。由于我们的应用未使用加密,它会在 Info.plist 文件中将 ITSAppUsesNonExemptEncryption 设置为 NO,并在你将应用发布到 TestFlight/Apple App Store 时管理相关的合规性检查。当你发布自己的应用并且使用了加密时,下次可以选择 N 来跳过此提示。

回复后,构建将排队,我们可以通过 EAS CLI 在 EAS 仪表板中提供的链接跟踪其进度:

🌐 After responding, the build will queue up, and we can track its progress via a provided link by the EAS CLI in the EAS dashboard:

构建详情页面包含什么内容?

构建详细信息页面显示构建类型、配置文件、Expo SDK 版本、应用版本、构建号、最后一次提交的哈希值,以及发起构建的开发者或账户所有者的身份。

🌐 The build details page displays the build type, profile, Expo SDK version, app version, build number, last commit hash, and the identity of the developer or account owner who initiated the build.

在上图中,构建产物 的当前状态显示构建正在进行中。完成后,此部分将提供下载构建的选项。日志 列出了在 EAS Build 上 iOS 构建过程中执行的每一步。为了简明起见,我们这里不会详细探讨每一步。要了解更多,请参见 iOS 构建过程

🌐 In the above image, the current status of the Build artifact shows that the build is in progress. Upon completion, this section will offer an option to download the build. The Logs outlines every step taken during the iOS build process on EAS Build. For the sake of brevity, we won't explore each step in detail here. To learn more, see iOS build process.

iOS 应用包标识符是什么?

ios.bundleIdentifier 是我们应用的唯一名称。如果我们现在发布应用,Apple App Store 将使用此属性及其值在商店中识别我们的应用。

🌐 The ios.bundleIdentifier is a unique name of our app. If we publish our app right now, the Apple App Store will use this property and its value to identify our app on the store.

这个符号被定义为 host.owner.app-name。例如,我们的示例应用有 com.owner.stickersmash,其中 com.owner 是域名,stickersmash 是我们的应用名称。

🌐 This notation is defined as host.owner.app-name. For example, our example app has com.owner.stickersmash where com.owner is the domain and stickersmash is our app name.

2

安装

🌐 Install

一旦构建完成,构建工件部分会更新,显示构建已完成:

🌐 Once the build finishes, the Build artifact section gets updated, indicating that the build is complete:

本节介绍了在 iOS 设备上运行开发构建的方法:Expo Orbit 和安装按钮。

🌐 This section provides the methods available for running the development build on an iOS device: Expo Orbit and Install button.

Expo Orbit 允许在 iOS 设备上无缝安装开发版本。使用此方法:

  • 使用 USB 将我们的 iOS 设备连接到开发机器。
  • 打开 Orbit 菜单栏应用。
  • 在 Orbit 应用中选择 设备
  • 在 EAS 仪表板上的 构建产物 下,点击 使用 Orbit 打开

安装构建后,Orbit 应用会在设备上启动开发构建版本。

🌐 After the build is installed, the Orbit app launches the development build on the device.

备用:使用安装按钮和二维码

构建产物部分的安装按钮会生成一个便于安装的二维码:

🌐 The Install button in the Build artifact section generates a QR code for easy installation:

  • 点击 安装 以显示带有二维码的弹出窗口。
  • 使用我们的 iOS 设备相机扫描二维码,然后点击链接在设备上下载开发版本。

3

运行

🌐 Run

在项目目录下运行 npx expo start 命令来启动开发服务器:

🌐 Start the development server by running the npx expo start command from the project directory:

Terminal
npx expo start
  • 在设备上,点击应用图标以打开开发版。
  • 通过确保我们同时登录了 EAS CLI 和开发版本来使用账户同步功能。由于我们已经登录了 EAS CLI,下一步是通过开发版本的用户界面登录。
  • 点击 获取开发服务器,然后从开发服务器列表中选择正在运行的服务器。

概括

🌐 Summary

Chapter 4: Create and run a cloud build for iOS device

我们成功地使用 EAS Build 在 iOS 设备上创建并运行了开发构建。

在下一章中,学习如何配置我们的应用设置,以在单个设备上安装多个应用版本。

Next: 配置多个应用变体