跳转至正文

Cordova Updater Cordova 插件

为 Cordova iOS 和 Android 提供与 capacitor-updater 相同的 API OTA Live Update 功能

安装

bun add @capgo/cordova-updater
npm、pnpm 或 yarn
  • npm install @capgo/cordova-updater
  • pnpm add @capgo/cordova-updater
  • yarn add @capgo/cordova-updater

指南

如何在 Cordova 中使用 Cordova Updater

使用 @capgo/cordova-updater

@capgo/cordova-updater 通过相同的 JavaScript API 为 Cordova iOS 和 Android 应用提供 Capgo Live Updates 功能, @capgo/capacitor-updater。安装 Cordova 插件,调用 notifyAppReady() 每次启动时,并使用以下方式上传 bundle: @capgo/cli.

安装

cordova plugin add @capgo/cordova-updater --variable APP_ID=com.example.app
cordova prepare android ios

基础用法

document.addEventListener('deviceready', async () => {
  const { Updater } = cordova.plugins;

  await Updater.notifyAppReady();

  const { bundle } = await Updater.current();
  console.log('Active bundle', bundle);

  const latest = await Updater.getLatest();
  if (latest.url && !latest.error) {
    const downloaded = await Updater.download({
      url: latest.url,
      version: latest.version,
      checksum: latest.checksum,
    });

    await Updater.next({ id: downloaded.id });
  }
});

平台要求

  • Cordova Android 13+ 以及 Cordova iOS 7+
  • 默认 Cordova WebView scheme(https://localhost/ Android 端, app://localhost/ iOS 端)
  • 避免使用 cordova-plugin-ionic-webview — 这会阻止 bundle 替换

部署新 bundle

bun run build
bunx @capgo/cli@latest bundle upload --channel=production

实践建议

  • 如果你同时发布 Capacitor 或 Electron 客户端,请复用相同的 Capgo App ID 和 channels。
  • 对待原生插件或 Cordova 平台的升级应视同其他原生变更:在 JavaScript bundle 调用新的原生 API 之前,请先发布新的应用商店二进制文件。
  • 完整的配置详情请参阅 Cordova updater 文档.

常见问题

Cordova Updater 插件常见问题

如何在 Cordova 应用中安装 Cordova Updater 插件?

运行 "bun add @capgo/cordova-updater"(或 "npm install @capgo/cordova-updater"),然后按指南和 GitHub README 中的 Cordova 安装步骤操作。

@capgo/cordova-updater 支持 React、Vue 和 Angular 吗?

可以。Cordova Updater 是一个 Cordova 包,因此适用于任何运行在 Cordova 里的 Web 框架:React、Vue、Angular、Svelte 以及纯 JavaScript。

@capgo/cordova-updater 是免费开源的吗?

是的。code 的源码公开在 GitHub 上:https://github.com/Cap-go/cordova-updater/,该包也可以在 npm 免费安装。欢迎提交 Bug 报告和 Pull Request。

无需等待 App Store 审核,即可发布 Cordova Updater 的变更

只要插件已包含在你的商店版本中,Capgo live updates 就能在几分钟内把 JavaScript、HTML 和 CSS 的改动推送给用户。

开始使用 Capgo