メインコンテンツへスキップ

スタートガイド

GitHub

AIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いの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.

手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:

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

ほとんどのユーザーには、以下の メインのクイックスタートガイド を参照することをお勧めします。これにはプラグインのインストールと Capgo のクラウド連携の両方が含まれています。

このガイドでは、仕組みの詳細な理解やセルフホストによるアップデートの実装を目指す上級者向けに、プラグインの技術的な詳細を解説します。

Capacitor Updaterプラグインを使用すると、Capacitor アプリケーションにOTA(Over-the-Air)アップデートが可能になります。これにより、アプリストアの審査を通さずにアップデートを配信できます。

  1. Bundleのダウンロード: プラグインがアップデート用のbundle(Webアセットを含むZIPファイル)をダウンロードします
  2. 展開: bundleがデバイスのストレージに展開されます
  3. ホットリロード: アプリを再起動することなく、新しいbundleに切り替わります
  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'
}
}
}

アップデートプロセスを詳細に制御する場合:

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

プラグインを以下で設定します: 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"
}

詳細は セルフホストモード の詳細についてはこちらを確認してください。

アップデートを完全に制御:

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() アプリの読み込みが正常に完了したとき
  • 本番環境へ反映する前に、アップデートを十分にテストしてください
  • ネットワークエラーに対する適切なエラーハンドリングを実装してください
  • バージョン番号は一貫性を持って使用してください
  • ダウンロードを高速化するため、bundleサイズを小さく保ってください
  • アップデートの成功率をモニタリングしてください

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド ネイティブプラグインの作業を計画するには、次と連携してください: @capgo/capacitor-updater を使用する 「@capgo/capacitor-updater を使用する」のネイティブ機能については、 Capgo プラグインディレクトリ Capgo プラグインディレクトリのプロダクトワークフローについては、 Capgo による Capacitor プラグイン Capgo による Capacitor プラグインの実装詳細については、 プラグインの追加または更新 プラグインの追加または更新における実装詳細については、および Ionic Enterprise プラグインの代替案 Ionic Enterprise プラグインの代替案におけるプロダクトワークフローについては。