This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

iOS 应用扩展

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


应用扩展允许你将自定义功能和内容扩展到你的应用之外,并在用户与其他应用或 iOS 系统功能交互时向他们提供。EAS Build 提供了在现有 React Native 项目和使用持续原生生成 (CNG)的项目中包含应用扩展的便利。

🌐 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 existing React Native projects and projects that use Continuous Native Generation (CNG).

CNG项目(实验支持)

🌐 CNG projects (experimental support)

一个典型的、简单的使用连续原生生成(CNG)的项目拥有一个应用目标且没有应用扩展。你可以通过编写一个配置插件(或使用创建了自己配置插件的扩展的库)向你的项目添加应用扩展。配置插件允许你在构建任务的“预构建”阶段向生成的 Xcode 项目中添加目标。

🌐 A typical, simple project that uses Continuous Native Generation (CNG) has 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" } } ] } } } } } } }

现有的 React Native 项目

🌐 Existing React Native projects

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

🌐 When you build an existing React Native 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.