跳过内容

使用 Cordova Updater 进行 Cordova

GitHub

本指南将指导您如何将 @capgo/cordova-updater 到一个Cordova应用中,以便在iOS和Android上接收Capgo实时更新。

Cordova Android 13+ 和/或 Cordova iOS 7+

一个 __CAPGO_KEEP_0__ 帐户(
  • CLI.app/register
  • 安装
  • 从 Capgo 安装插件并传入您的 __CAPGO_KEEP_1__ 应用程序 ID:capgo.app/register)
  1. Install the plugin from npm and pass your Capgo app 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 });
}
});

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+ 以及默认方案

上传您的第一个捆绑包

标题:“上传您的第一个捆绑包”

构建您的Web资产,然后使用 Capgo CLI (与 Capacitor 的相同工作流程) 上传:

终端窗口
bun run build
bunx @capgo/cli@latest bundle upload --channel=production
  • 与 __CAPGO_KEEP_0__ 更新器配置进行比较 Capacitor updater configuration — 大多数选项映射到 plugin.xml 变量。
  • 阅读 实时更新兼容性 在发布本机插件更改之前
  • 迁移到 Capacitor 后?保持相同的 Capgo 应用 ID 和频道;仅客户端插件包发生变化。