指南
如何在 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 文档.