跳过内容

Auto Update

GitHub

本文档将解释如何运行您的自动更新服务器。

确保您的捆绑包通过 HTTPS 服务,并且服务器有正确的 CORS 头来允许应用程序下载更新。 例如: https://myserver.com/app/updates/updates.json

如果您不熟悉服务捆绑包,我们建议您尝试 Capgo Cloud 或查看示例:

配置

配置项

添加一个 updateUrl 到你的 capacitor.config.json.

{
"plugins": {
"CapacitorUpdater": {
"updateUrl": "https://myserver.com/app/updates/updates.json",
}
}
}

更新 API

更新 API

插件将每次打开应用时,向你的 API 发送一个 POST 请求,请求体如下:

interface AppInfos {
"platform": "ios" | "android" | "electron",
"device_id": "UUID_of_device_unique_by_install",
"app_id": "APPID_FROM_CAPACITOR_CONFIG",
"custom_id": "your_custom_id_set_on_runtime",
"plugin_version": "PLUGIN_VERSION",
"version_build": "VERSION_NUMBER_FROM_NATIVE_CODE",
"version_code": "VERSION_CODE_FROM_NATIVE_CODE",
"version_name": "LAST_DOWNLOADER_VERSION" | "builtin"
"version_os": "VERSION_OF_SYSTEM_OS",
"is_emulator": boolean,
"is_prod": boolean,
}

The server API 应该以 JSON 格式响应,向 capacitor-updater 插件提供数据。通过此数据,如果需要更新:

{
"version": "1.2.3",
"url": "https://myserver.com/app/updates/my-new-app-2.0.0.zip",
"checksum": "sha256_checksum_of_bundle"
}

在自动更新模式下,服务器应该比较版本并返回正确的版本,如果 URL 键存在,插件将启动下载过程。

如果您添加“message”和“error”键,版本将不会被设置,消息将在日志中显示而不是版本。

version 键应该位于 semver 格式。

zip 文件应该有 index.html 作为根目录的文件,或者根目录只有一个文件夹,文件夹内有 index.html 您可以使用 __CAPGO_KEEP_0__ 命令对您的捆绑包进行压缩:

You can use the command of the CLI to zip your bundle:

复制到剪贴板
npx @capgo/cli bundle zip --path [/path/to/my/bundle]

生成包文件校验和

生成包文件校验和

重要: You must use the Capgo CLI to create your bundle zip file. The Capgo plugin requires a specific zip format and structure that is only guaranteed when using the official CLI tool. Standard zip utilities may create incompatible archives.

要为您的包生成校验和,请使用 Capgo CLI zip 命令并指定 --json 标志:

创建包含校验和信息的包
npx @capgo/cli bundle zip [appId] --json

此命令将:

  • 创建与 Capgo 插件兼容的正确格式的 zip 文件
  • 生成 SHA256 校验和以进行完整性验证
  • 以 JSON 格式输出包信息

示例输出:

{
"version": "1.2.3",
"checksum": "a1b2c3d4e5f6789...",
"size": 1234567
}

使用 checksum 将此输出中的值用于您的API响应,以便在安装之前确保插件可以验证捆绑包完整性。

从自动更新继续

标题:从自动更新继续

如果您正在使用 自动更新 来规划迁移和企业操作,连接它到 使用@capgo/capacitor-updater 为native能力在使用@capgo/capacitor-updater Capgo企业 为Capgo企业版产品工作流程 Ionic 企业版插件替代方案 为Ionic 企业版插件替代方案的产品工作流程 Capgo替代方案 为Capgo替代方案的产品工作流程,和 Capgo咨询 为Capgo咨询的产品工作流程