了解如何使用 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.
¥Prerequisites
在我们开始之前,请确保你拥有:
¥Before we begin, ensure you have:
苹果开发者账户:这是访问 必要的凭证 来签署我们的应用所必需的,因为每个构建都需要进行签名以验证应用是否来自可信来源。EAS Build 有助于管理这些凭证。
¥Apple Developer Account: This is required to access necessary credentials for signing our app, as each build needs to be signed to verify that the app comes from a trusted source. EAS Build helps manage these credentials.
在 iOS 16 及更高版本上激活开发者模式:在你的设备上安装开发版本需要启用开发者模式。如果这是你第一次或者当前已禁用,请参阅 激活开发者模式 的这些说明。
¥Developer Mode activated on iOS 16 and higher: Installing development builds on your device requires Developer Mode to be enabled. If this is your first time or if it's currently disabled, see these instructions to activate Developer Mode.
¥Provisioning profile
要在 iOS 设备上启动开发,我们必须:
¥To initiate development on an iOS device, we have to:
通过创建新的 配置文件 来注册设备。
¥Register the device by creating a new provisioning profile.
下载此配置文件并将其安装到设备上。
¥Download and install this profile onto the device.
1
¥Register an iOS device
使用 EAS CLI,运行命令来注册新的 Apple 设备:
¥With EAS CLI, run the command to register a new Apple device:
-
eas device:create
该命令提示我们以下问题
¥This command prompts us with the following questions
你位于项目目录中。你想使用你的账户名账户吗?按 Y。
¥You're inside the project directory. Would you like to use the your-account-name account? Press Y.
苹果 ID。在此步骤中,请输入你的 Apple ID。然后它将登录到我们的 Apple 开发者账户。按照终端窗口中的步骤操作。
¥Apple ID. For this step, enter your Apple ID. It will then log in to our Apple Developer account. Follow the steps in the terminal window.
你希望如何注册你的设备?选择生成可在 iOS 设备上打开的注册 URL 的网站。
¥How would you like to register your devices? Select Website that generates a registration URL that can be opened on the iOS device.
提示:如果你或你的团队拥有多台设备,你可以与这些设备共享配置文件链接以下载和安装配置文件。
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.
安装配置文件后,我们的设备会将我们重定向回 Web 浏览器,显示一条成功消息,表明该过程已完成。
¥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.
¥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:
eas.json 中的 developmentClient
设置为 true
,这是通过默认配置完成的。
¥The developmentClient
is set to true
in eas.json, which is done by the default configuration.
然后,运行 eas build
命令,其中 ios
作为平台,development
作为构建配置文件:
¥Then, run the eas build
command with ios
as the platform and development
as the build profile:
-
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 包标识符是什么?按 return 选择为此提示提供的默认值。如果尚未定义,这将在 app.json 中添加 ios.bundleIdentifier
。
¥What would you like your iOS bundle identifier to be? Press return to select the default value provided for this prompt. This will add ios.bundleIdentifier
in app.json if it isn't already defined.
登录我们的苹果开发者账户。由于我们是第一次创建开发版本,因此它会要求我们生成新的 Apple 分发证书。按 Y。
¥Log in to our Apple Developer account. Since we are creating a development build for the first time, it will ask us to Generate a new Apple Distribution Certificate. Press Y.
选择用于临时构建的设备。这是关键部分,这就是为什么我们之前必须注册一个配置文件。我们可以在此处选择一个或所有已注册的设备,然后按回车键稍后在这些设备上安装该版本。
¥Select a device for ad hoc build. This is the key part, which is why we had to register a provisioning profile before. We can select one or all of our registered devices here and then press return to install that build on those devices later.
响应后,构建将排队,我们可以通过 Expo 仪表板中 EAS CLI 提供的链接跟踪其进度:
¥After responding, the build will queue up, and we can track its progress via a provided link by the EAS CLI in the Expo 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.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 轨道和安装按钮。
¥This section provides the methods available for running the development build on an iOS device: Expo Orbit and Install button.
Expo 轨道 允许在 iOS 设备上无缝安装开发版本。要使用此方法:
¥Expo Orbit allows for seamless installation of the development build on an iOS device. To use this method:
使用 USB 将我们的 iOS 设备连接到我们的开发者机器。
¥Connect our iOS device to our developer machine using USB.
打开 Orbit 菜单栏应用。
¥Open the Orbit menu bar app.
在 Orbit 应用中选择设备。
¥Select the Device in the Orbit app.
在 Expo 仪表板上的“构建工件”下,单击“使用 Orbit 打开”。
¥On the Expo dashboard, under Build artifact, click the Open with Orbit.
安装版本后,Orbit 应用会在设备上启动开发版本。
¥After the build is installed, the Orbit app launches the development build on the device.
3
¥Run
通过从项目目录运行 npx expo start
命令来启动开发服务器:
¥Start the development server by running the npx expo start
command from the project directory:
-
npx expo start
在设备上,点击应用图标以打开开发版本。
¥On the device, tap the app icon to open the development build.
通过确保我们登录 EAS CLI 和开发版本来使用账户同步功能。由于我们已经登录 EAS CLI,下一步是通过开发版本的 UI 登录。
¥Use the account syncing feature by ensuring we're logged into both the EAS CLI and development build. As we're already logged into the EAS CLI, the next step is to log in through the UI of your development build.
点击获取开发服务器,然后从开发服务器下的列表中选择正在运行的服务器。
¥Tap Fetch development servers and select the server running from the list under Development servers.
¥Summary
Chapter 4: Create and run a cloud build for iOS device
We successfully used EAS Build to create and run development builds on iOS devices.
In the next chapter, learn how to configure our app config to install multiple app variants on a single device.