iOS 应用扩展

了解如何将应用扩展与 EAS Build 结合使用来添加自定义功能。


应用扩展允许你将自定义功能和内容扩展到你的应用之外,并在用户使用其他应用或 iOS 系统功能时提供给他们。EAS Build 提供了在裸项目和托管项目中包含应用扩展的便利功能。

🌐 App extensions let you extend custom functionality and content beyond your app and make it available to users while they're interacting with other apps or iOS system functionality. EAS Build provides affordances for including app extensions in both bare and managed projects.

主持项目(实验支持)

🌐 Managed projects (experimental support)

一个典型的、简单的托管项目,我们只有一个应用目标,没有应用扩展。你可以通过编写一个 配置插件(或使用一个带有自己配置插件的库来创建扩展)将应用扩展添加到你的项目中。配置插件让你可以在构建任务的“预构建”阶段向生成的 Xcode 项目中添加目标。

🌐 A typical, simple managed project we have a single application target and no app extensions. You can add an app extension to your project by writing a config plugin (or using a library that creates an extension with its own config plugin). Config plugins let you add targets to the Xcode project that is generated during the "Prebuild" phase of a build job.

在你的应用配置中使用 extra.eas.build.experimental.ios.appExtensions 声明应用扩展,使 EAS CLI 能在构建开始之前(Xcode 项目生成之前)了解有哪些应用扩展,以确保所需的凭证被生成和验证。配置插件也能够修改应用配置,而且在大多数情况下,如果你使用的库添加了一个扩展,配置插件也会在你的应用配置中添加声明该扩展所需的配置。如果你正在编写一个库,我们建议你考虑这一点。以下是如果直接在 app.json 中声明,这将会是什么样的示例:

🌐 Declaring app extensions with extra.eas.build.experimental.ios.appExtensions in your app config makes it possible for EAS CLI to know what app extensions exist before the build starts (before the Xcode project has been generated) to ensure that the required credentials are generated and validated. Config plugins are also able to modify the app config, and in most cases, if you are using a library that adds an extension then the config plugin will also add the required configuration to declare the extension in your app config. If you are writing a library, we recommend that you consider this. The following is an example of what this would look like if it were declared directly in app.json:

app.json
{ "expo": { ... "extra": { "eas": { "build": { "experimental": { "ios": { "appExtensions": [ { "targetName": "myappextension", "bundleIdentifier": "com.myapp.extension", "entitlements": { "com.apple.example": "entitlement value" } } ] } } } } } } }

裸项目

🌐 Bare projects

当你构建一个空项目时,EAS CLI 会自动检测你 Xcode 项目中配置的应用扩展,并为每个目标生成所有必要的凭证,或者你可以在 credentials.json 中提供它们。更多信息,请参见 多目标项目

🌐 When you build a bare project, EAS CLI will automatically detect app extensions configured in your Xcode project and generate all necessary credentials for each target, or you can provide them in credentials.json For more information, see Multi target project.