Cordova Updater 入门指南
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
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/register)
-
从 npm 安装插件,并传入你的 Capgo App ID:
终端窗口 cordova plugin add @capgo/cordova-updater --variable APP_ID=YOUR_CAPGO_APP_ID -
可选:安装时覆盖默认值(变量与 Capacitor updater 相同):
终端窗口 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
快速入门
章节标题为“快速入门”document.addEventListener('deviceready', async () => { await cordova.plugins.Updater.notifyAppReady();});常见坑点
章节标题为“常见陷阱”- 请勿将此插件与 cordova-plugin-ionic-webview 一起使用。
- 调用
notifyAppReady()在 bundle 加载后立即执行——赶在繁重的 UI 工作拖慢回滚窗口之前。 - 确保 Cordova scheme 设置正确。
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/scheme。 - 该插件注册了一个
CordovaPluginPathHandler用于提供已下载的 bundle 资源。
- 需要 Cordova iOS 7+,并使用默认的
app://localhost/scheme。 - 该插件实现了
CDVPluginSchemeHandler以拦截 bundle 请求。
上传你的第一个 bundle
“上传你的第一个 bundle”部分构建你的 Web 资源,然后用 Capgo CLI 上传(工作流与 Capacitor 相同):
bun run buildnpx @capgo/cli@latest bundle upload --channel=production后续步骤
“下一步”章节- 与以下设置进行对比 Capacitor updater 配置 — 大多数选项对应
plugin.xml变量。 - 读取 Live update 兼容性 在发布原生插件变更之前。
- 以后要迁移到 Capacitor?保持相同的 Capgo 应用 ID 和通道不变;只需更换客户端插件包。