跳过内容

使用 Cordova Updater 进行入门

GitHub

本指南将指导您添加 @capgo/cordova-updater 到 Cordova 应用程序中,以便您可以在 iOS 和 Android 上接收 Capgo 实时更新。

标题为“前提条件”

Cordova __CAPGO_KEEP_0__ 12+
  1. 从 npm 安装插件,并传递您的 Capgo 应用 ID:

    终端窗口
    cordova plugin add @capgo/cordova-updater --variable APP_ID=YOUR_CAPGO_APP_ID
  2. 可选:在安装时覆盖默认值(同 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
  3. 更改插件变量后准备原生项目:

    终端窗口
    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 });
}
});

TypeScript 类型随 npm 包一起提供:

import type { UpdaterPlugin } from '@capgo/cordova-updater';
declare const cordova: { plugins: { Updater: UpdaterPlugin } };

平台说明

平台说明
  • 需要 Cordova Android 13+ 才能将 WebView 从默认方案中服务。 https://localhost/ 方案。
  • 将下载的包资产注册为 CordovaPluginPathHandler 将下载的包资产注册为

Build your web assets, then upload with the Capgo CLI (same workflow as Capacitor):

终端窗口
bun run build
bunx @capgo/cli@latest bundle upload --channel=production

下一步

下一步
  • __CAPGO_KEEP_0__ 升级器配置 Capacitor updater configuration 变量。 plugin.xml 阅读
  • 直播更新兼容性 在发布本机插件更改之前 迁移到 __CAPGO_KEEP_0__ 后?保持相同的 __CAPGO_KEEP_1__ 应用 ID 和频道;仅客户端插件包发生变化。
  • Migrating to Capacitor later? Keep the same Capgo app ID and channels; only the client plugin package changes.