Getting Started
Ce contenu n'est pas encore disponible dans votre langue.
Installation
Section titled “Installation”npm install @capgo/capacitor-updaternpx cap syncyarn add @capgo/capacitor-updaternpx cap syncpnpm add @capgo/capacitor-updaternpx cap syncbun add @capgo/capacitor-updaternpx cap syncQuick Start
Section titled “Quick Start”For most users, we recommend following the main Quickstart guide which covers both the plugin installation and Capgo cloud integration.
This getting-started guide focuses on the technical plugin details for advanced users who want to understand the underlying mechanisms or implement self-hosted updates.
Overview
Section titled “Overview”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.
How It Works
Section titled “How It Works”- Bundle Download: The plugin downloads update bundles (ZIP files containing your web assets)
- Extraction: Bundles are extracted to the device’s storage
- Hot Reload: The app switches to the new bundle without requiring a restart
- Fallback: If an update fails, the app reverts to the previous working version
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.tsAdd to your capacitor.config.ts:
{ plugins: { CapacitorUpdater: { autoUpdate: true, updateUrl: 'https://your-update-server.com/api/updates' } }}2. Manual Mode
Section titled “2. Manual Mode”For advanced control over the update process:
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();Platform Configuration
Section titled “Platform Configuration”No additional configuration required. The plugin works out of the box.
Android
Section titled “Android”No additional configuration required. The plugin works out of the box.
Basic API Usage
Section titled “Basic API Usage”Download an Update
Section titled “Download an Update”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 Active Bundle
Section titled “Set Active Bundle”// Set bundle to be used on next app startawait CapacitorUpdater.set({ id: bundle.id});Reload with New Bundle
Section titled “Reload with New Bundle”// Reload app immediately with new bundleawait CapacitorUpdater.reload();List Bundles
Section titled “List Bundles”const { bundles } = await CapacitorUpdater.list();console.log('Available bundles:', bundles);Delete a Bundle
Section titled “Delete a Bundle”await CapacitorUpdater.delete({ id: 'bundle-id'});Get Current Bundle
Section titled “Get Current Bundle”const { bundle } = await CapacitorUpdater.current();console.log('Current bundle:', bundle.version);Event Listeners
Section titled “Event Listeners”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);});Configuration Options
Section titled “Configuration Options”Configure the plugin in your capacitor.config.ts:
{ plugins: { CapacitorUpdater: { // Auto-update settings autoUpdate: true, updateUrl: 'https://api.example.com/updates',
// Update behavior resetWhenUpdate: true, directUpdate: false,
// Version settings version: '1.0.0',
// Security allowModifyUrl: false,
// Stats collection statsUrl: 'https://api.example.com/stats',
// Channel (for Capgo cloud) defaultChannel: 'production' } }}Integration Patterns
Section titled “Integration Patterns”With Capgo Cloud
Section titled “With Capgo Cloud”The easiest way to get started:
// Install the Capgo CLInpm install -g @capgo/cli
// Login to Capgonpx @capgo/cli login
// Upload your first bundlenpx @capgo/cli bundle upload
// The plugin auto-updates from Capgo cloudSee the main Quickstart guide for details.
Self-Hosted Updates
Section titled “Self-Hosted Updates”Host your own update server:
// Configure your update endpoint{ plugins: { CapacitorUpdater: { autoUpdate: true, updateUrl: 'https://your-server.com/api/check-update' } }}Your server should return:
{ "version": "1.0.1", "url": "https://your-server.com/updates/1.0.1.zip"}See Self-Hosted Mode for complete details.
Manual Update Flow
Section titled “Manual Update Flow”Complete control over updates:
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();}Best Practices
Section titled “Best Practices”- Always call
notifyAppReady()when your app successfully loads - Test updates thoroughly before pushing to production
- Implement proper error handling for network failures
- Use version numbers consistently
- Keep bundle sizes small for faster downloads
- Monitor update success rates
Next Steps
Section titled “Next Steps”- Plugin API Reference - Complete API documentation
- Plugin Settings - All configuration options
- Events - Available update events
- Self-Hosted Mode - Run your own update server
- Local Development - Test updates locally
- Debugging - Troubleshooting guide
Support
Section titled “Support”- Known Issues - Common problems and solutions
- GitHub Discussions - Community support
- Discord - Real-time chat