__CAPGO_KEEP_0__ - __CAPGO_KEEP_1__ アプリ用のリアルタイム更新

Getting Started

GitHub

AI-Assisted セットアップを使用してプラグインをインストールできます。AI ツールに Capgo スキルを追加するには、以下のコマンドを実行してください。

ターミナル画面
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.

Manual セットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。

ターミナルウィンドウ
bun add @capgo/capacitor-updater
bunx cap sync

大多数のユーザーにとって、Capgoを使用するには、Capacitorのドキュメントを参照することをお勧めします。 main Quickstart guide which covers both the plugin installation and Capgo cloud integration.

このスタートガイドは、プラグインの技術的な詳細についての理解や、自社で更新を実装したいユーザー向けに焦点を当てています。

Capacitor Updater プラグインは、Capacitor アプリケーションに対してオーバー・ザ・エア(OTA)更新を可能にします。これにより、アプリをアプリストアのレビューを経ることなく、更新をユーザーに配信できます。

How It Works

「How It Works」
  1. Bundle Download: プラグインは、更新パッケージ(ZIPファイルに含まれるWebアセット)をダウンロードします。
  2. Extraction: パッケージは、デバイスのストレージに展開されます。
  3. Hot Reload: アプリは新しいバンドルに切り替わり、再起動が必要なくなる
  4. Fallback: アップデートが失敗した場合、前の正常に動作していたバージョンに戻る

Usage Modes

使用方法
1. 自動更新モード (推奨)

自動更新管理とともにプラグインを使用する最も簡単な方法:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Plugin handles everything automatically
// Configure in capacitor.config.ts

Add to your capacitor.config.ts:

{
plugins: {
CapacitorUpdater: {
autoUpdate: 'atBackground',
updateUrl: 'https://your-update-server.com/api/updates'
}
}
}

更新プロセスの高度な制御が必要な場合:

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();

追加の設定は必要ありません。プラグインは箱から出てきます。

追加の設定は必要ありません。プラグインは箱から出てきます。

アップデートをダウンロード

アップデートをダウンロードのセクション
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);
});

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

メインのクイックスタートガイド 詳細については。

自社の更新サーバーをホストしてください。

// 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() 成功した更新をテストする
  • プロダクションにプッシュする前に更新を徹底的にテストする
  • ネットワークエラーの際に適切なエラーハンドリングを実装する
  • バージョン番号を一貫して使用する
  • ダウンロードが速くなるようにバンドルサイズを小さくする
  • 更新の成功率を監視する

次のステップ

次のステップ

サポート

サポート

Getting Startedから続けて

Getting Startedから続けて

Capgoを使用している場合 スタートガイド __CAPGO_KEEP_0__を使用してネイティブプラグインの作業を計画し、接続する @capgo/capacitor-updaterを使用する ネイティブ機能の使用方法については、@capgo/capacitor-updaterを参照してください Capgo プラグインディレクトリ Capgo プラグインディレクトリを使用して製品ワークフローを実装する Capacitor プラグイン by Capgo Capacitor プラグイン by Capgo を使用して実装詳細を確認する プラグインの追加または更新 プラグインの追加または更新の実装詳細については、 イオニック エンタープライズ プラグインの代替 イオニック エンタープライズ プラグインの代替を使用して製品ワークフローを実装する