首页指南参考教程

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.

Expo 中文网 - 粤ICP备13048890号