跳过主要内容
返回到插件
@capgo/cordova-updater
教程
@capgo/cordova-updater

Cordova 更新器

Cordova iOS 和 Android 的 OTA 实时更新,使用相同的 API 为 capacitor-updater

指南

Cordova Updater的教程

使用@capgo/cordova-updater

@capgo/cordova-updater Capgo将实时更新功能带给Cordova iOS和Android应用,使用相同的JavaScriptAPI @capgo/capacitor-updater安装Cordova插件,调用 notifyAppReady() 在每次启动时调用,并上传 @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 方案(https://localhost/ 在 Android 上, app://localhost/ 在 iOS 上)
  • 避免 cordova-plugin-ionic-webview — 这会阻止 bundle 交换

部署一个新的 bundle

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

实用建议

  • Reuse the same Capgo app ID and channels if you also ship a Capacitor or Electron client.
  • 像任何其他本机更改一样处理本机插件或 Cordova 平台升级:在 JavaScript 包中依赖新本机 API 之前,发布一个新的商店二进制文件。
  • 完整的设置细节在 Cordova 更新器文档.