开始
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-updater`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/updater/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题为“安装”您可以使用我们的AI辅助设置来安装插件。将Capgo技能添加到您的AI工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-updater` plugin in my project.如果您更喜欢手动设置,请运行以下命令并按照以下平台特定的说明进行安装:
bun add @capgo/capacitor-updaterbunx cap syncyarn add @capgo/capacitor-updaterbunx cap syncpnpm add @capgo/capacitor-updaterbunx cap syncbun add @capgo/capacitor-updaterbunx cap sync快速入门
快速入门对于大多数用户,我们建议遵循 主快速入门指南 它涵盖了插件安装和Capgo云集成。
本指南侧重于技术插件细节,适合高级用户了解底层机制或实现自主更新。
概述
概述The Capacitor Updater plugin enables over-the-air (OTA) updates for your Capacitor applications. This allows you to push updates to your app without going through app store reviews.
如何工作
如何工作- 下载包:
- Extraction:
- Hot Reload:
- Fallback:
Usage Modes
Section titled “Usage Modes”1. Auto-Update Mode (Recommended)
Section titled “1. Auto-Update Mode (Recommended)”The simplest way to use the plugin with automatic update management:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Plugin handles everything automatically// Configure in capacitor.config.ts添加到您的 capacitor.config.ts:
{ plugins: { CapacitorUpdater: { autoUpdate: 'atBackground', updateUrl: 'https://your-update-server.com/api/updates' } }}2. 手动模式
标题:2. 手动模式对于更新过程的高级控制:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Download an updateconst bundle = await CapacitorUpdater.download({ url: 'https://your-server.com/updates/v1.0.1.zip', version: '1.0.1'});
// Set the bundle (will be used on next app start)await CapacitorUpdater.set({ id: bundle.id});
// Or reload immediatelyawait CapacitorUpdater.reload();平台配置
标题:平台配置iOS
标题:iOS不需要任何额外的配置。插件可以直接使用。
Android
Android无需额外配置。插件可以直接使用。
基本API使用
基本API使用下载更新
下载更新import { CapacitorUpdater } from '@capgo/capacitor-updater';
const bundle = await CapacitorUpdater.download({ url: 'https://example.com/update.zip', version: '1.0.1'});
console.log('Downloaded bundle:', bundle.id);设置活动包
设置活动包// Set bundle to be used on next app startawait CapacitorUpdater.set({ id: bundle.id});复制到剪贴板
Section titled “重新加载新包”// Reload app immediately with new bundleawait CapacitorUpdater.reload();const { bundles } = await CapacitorUpdater.list();console.log('Available bundles:', bundles);await CapacitorUpdater.delete({ id: 'bundle-id'});const { bundle } = await CapacitorUpdater.current();console.log('Current bundle:', bundle.version);Listen for update events:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Listen for download progressCapacitorUpdater.addListener('download', (info) => { console.log('Download progress:', info.percent);});
// Listen for download completionCapacitorUpdater.addListener('downloadComplete', (bundle) => { console.log('Download complete:', bundle.version);});
// Listen for update failuresCapacitorUpdater.addListener('updateFailed', (error) => { console.error('Update failed:', error);});
// Listen for successful updatesCapacitorUpdater.addListener('updateAvailable', (info) => { console.log('Update available:', info.version);});Configure the plugin in your capacitor.config.ts:
{ plugins: { CapacitorUpdater: { // Auto-update settings autoUpdate: 'atBackground', updateUrl: 'https://api.example.com/updates',
// Update behavior resetWhenUpdate: true,
// Version settings version: '1.0.0',
// Security allowModifyUrl: false,
// Stats collection statsUrl: 'https://api.example.com/stats',
// Channel (for Capgo cloud) defaultChannel: 'production' } }}With Capgo Cloud
Section titled “With Capgo Cloud”The easiest way to get started:
// Install the Capgo CLIbun add -g @capgo/cli
// Login to Capgonpx @capgo/cli login
// Upload your first bundlenpx @capgo/cli bundle upload
// The plugin auto-updates from Capgo cloud查看 主页快速入门指南 详细信息。
自主更新
标题为“自主更新”在您的服务器上托管更新服务器:
// Configure your update endpoint{ plugins: { CapacitorUpdater: { autoUpdate: 'atBackground', updateUrl: 'https://your-server.com/api/check-update' } }}您的服务器应返回:
{ "version": "1.0.1", "url": "https://your-server.com/updates/1.0.1.zip"}查看 自主模式 了解更多详细信息。
手动更新流程
手动更新流程对更新有完全的控制权:
import { CapacitorUpdater } from '@capgo/capacitor-updater';
async function checkAndUpdate() { // Check for updates from your server const response = await fetch('https://api.example.com/check-update'); const { version, url } = await response.json();
// Download the update const bundle = await CapacitorUpdater.download({ url, version });
// Notify bundle is ready await CapacitorUpdater.notifyAppReady();
// Set as next version await CapacitorUpdater.set({ id: bundle.id });
// Reload when ready await CapacitorUpdater.reload();}最佳实践
手动更新流程- 当您的应用程序成功加载时
notifyAppReady()在推送到生产环境之前测试更新 - 实现网络故障时的适当错误处理
- 一致使用版本号
- 手动更新流程
- 保持包大小小以便快速下载
- 监控更新成功率
下一步
下一步- Plugin API Reference - Complete API documentation
- 插件设置 所有配置选项
- 事件 可用更新事件
- 自主托管模式 运行自己的更新服务器
- 本地开发 - 在本地测试更新
- 调试 - 故障排除指南
支持
-- 支持 -
- GitHub Discussions - 常见问题和解决方案
- __CAPGO_KEEP_0__ 讨论 - 社区支持
继续从 Getting Started
标题:继续从 Getting Started如果您正在使用 Getting Started 来规划原生插件工作,连接它与 使用 @capgo/capacitor-updater 为原生能力在使用 @capgo/capacitor-updater 中 Capgo 插件目录 为产品工作流程在 Capgo 插件目录 中 Capacitor 插件由 Capgo 为实现细节在 Capacitor 插件由 Capgo 中 添加或更新插件 了解如何在添加或更新插件的过程中实现详细信息, Ionic企业插件的替代品 了解Ionic企业插件的产品工作流程