指南
如何在Cordova中使用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— 这会阻止捆绑包交换
部署一个新捆绑包
bun run build
bunx @capgo/cli@latest bundle upload --channel=production
实用建议
- 若您还部署了 Capacitor 或 Electron 客户端,请重用相同的 Capgo 应用 ID 和频道。
- 将原生插件或 Cordova 平台升级视为任何原生更改:在 JavaScript 包中使用新原生 API 之前,先部署一个新的商店二进制文件。
- 详细的设置信息在 Cordova 更新器文档 .