Cordova Updater
复制一个安装提示,包含安装步骤和该插件的完整Markdown指南。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/cordova-updater`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/cordova-updater/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
本指南将指导您添加 @capgo/cordova-updater 到一个Cordova应用中,以便您可以在iOS和Android上接收Capgo实时更新。
前提条件
前提条件- Cordova CLI 12+
- Cordova Android 13+ 和/或 Cordova iOS 7+
- 一个 Capgo 账户 (capgo.app/注册)
安装
安装-
从 npm 安装插件,并传递您的 Capgo 应用 ID:
终端窗口 cordova plugin add @capgo/cordova-updater --variable APP_ID=YOUR_CAPGO_APP_ID -
可选:在安装时覆盖默认值(同 Capacitor 更新器中的变量):
终端窗口 cordova plugin add @capgo/cordova-updater \--variable APP_ID=YOUR_CAPGO_APP_ID \--variable DEFAULT_CHANNEL=production \--variable UPDATE_URL=https://plugin.capgo.app/updates \--variable AUTO_UPDATE=atBackground -
更改插件变量后准备本机项目:
终端窗口 cordova prepare android ios
JavaScript 使用
标题:JavaScript 使用之后 deviceready,该插件可作为 cordova.plugins.Updater:
document.addEventListener('deviceready', async () => { const { Updater } = cordova.plugins;
await Updater.notifyAppReady();
const latest = await Updater.getLatest(); if (latest.url && !latest.error) { const bundle = await Updater.download({ url: latest.url, version: latest.version, checksum: latest.checksum, });
await Updater.next({ id: bundle.id }); }});npm 包中包含 TypeScript 类型:
import type { UpdaterPlugin } from '@capgo/cordova-updater';
declare const cordova: { plugins: { Updater: UpdaterPlugin } };平台说明
标题为“平台说明”- 需要 Cordova Android 13+,因此 WebView 从默认
https://localhost/方案中服务。 - 该插件注册一个
CordovaPluginPathHandler来服务下载的捆绑包资产。
- 需要 Cordova iOS 7+ 的默认
app://localhost/方案。 - 插件实现
CDVPluginSchemeHandler拦截捆绑请求。
上传您的第一个捆绑包
标题:上传您的第一个捆绑包构建您的 Web 资产,然后使用 Capgo CLI (与 Capacitor 的相同工作流程) 上传:
bun run buildbunx @capgo/cli@latest bundle upload --channel=production下一步
上下文:Capgo Builder / 原生云构建产品页面。角色:短 UI 标签或导航项。消息键 `native_build_builder_credit_next` (原生构建构建器信用下一步)。- 标题:下一步骤 Capacitor 升级器配置 — 大多数选项映射到
plugin.xml变量。 - 查看 Live update 兼容性 context
- 迁移到 Capacitor 后? 保持相同的 Capgo 应用 ID 和频道; 只有客户端插件包发生了变化。