コンテンツにジャンプ

はじめに

クリップボードにコピー
bun add @capgo/capacitor-updater
bunx cap sync

大多数のユーザーにとって、プラグインのインストールと__CAPGO_KEEP_0__クラウド統合をカバーする 主なクイックスタートガイド which covers both the plugin installation and Capgo cloud integration.

advanced users who want to understand the underlying mechanisms or implement self-hosted updates.

概要

概要

Capacitor アップデーター プラグインは、Capacitor アプリケーションに対してオーバー・ザー・アイアー (OTA) アップデートを有効にします。これにより、App Store のレビューの手順を経ることなく、アプリにアップデートをプッシュできます。

しくみ

しくみ
  1. バンドルダウンロード: プラグインは、更新バンドル (ZIP ファイルに含まれる Web アセット) をダウンロードします。
  2. 抽出: バンドルは、デバイスのストレージに抽出されます。
  3. ホットリロード: アプリは、新しいバンドルに切り替わり、再起動が必要なくなる。
  4. フォールバック: アップデートが失敗した場合、 アプリは前の正常に動作していたバージョンに戻ります。
「1. 自動アップデートモード (推奨)」セクション

自動アップデート管理とともにプラグインを使用する最も簡単な方法です。

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. 手動モード」セクション

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Download an update
const 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 immediately
await 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 start
await CapacitorUpdater.set({
id: bundle.id
});

新しいバンドルでリロード

新しいバンドルでリロード
// Reload app immediately with new bundle
await 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);

イベントリスナー

イベントリスナー

更新イベントをリスンする

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Listen for download progress
CapacitorUpdater.addListener('download', (info) => {
console.log('Download progress:', info.percent);
});
// Listen for download completion
CapacitorUpdater.addListener('downloadComplete', (bundle) => {
console.log('Download complete:', bundle.version);
});
// Listen for update failures
CapacitorUpdater.addListener('updateFailed', (error) => {
console.error('Update failed:', error);
});
// Listen for successful updates
CapacitorUpdater.addListener('updateAvailable', (info) => {
console.log('Update available:', info.version);
});

設定オプション

バンドを削除する

プラグインを設定する 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'
}
}
}

始めるには最も簡単な方法:

// Install the Capgo CLI
bun add -g @capgo/cli
// Login to Capgo
npx @capgo/cli login
// Upload your first bundle
npx @capgo/cli bundle upload
// The plugin auto-updates from Capgo cloud

詳細は 「Quickstartの主なガイド」 を参照してください。

自社のアップデートサーバーをホストする:

// 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"
}

詳細を見る Self-Hosted Mode 詳細は「Self-Hosted Mode」でご確認ください。

Manual Update Flow

「Manual Update Flow」

アップデートの完全な制御:

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() アプリが正常に起動したときに
  • テストを徹底的に行って、生産環境にプッシュする前に
  • ネットワークエラーの際に適切なエラーハンドリングを実装する
  • バージョン番号を一貫して使用する
  • ダウンロードが速くなるように、バンドルサイズを小さく保つ
  • アップデートの成功率を監視する

次のステップ

次のステップ