내용으로 건너뛰기

이벤트

GitHub

Capacitor 업데이터 플러그인은 업데이트 프로세스를 모니터링하고 다양한 상태에 반응하기 위해 듣기할 수 있는 여러 이벤트를 제공합니다.

이벤트 리스너 설정

이벤트 리스너 설정

업데이트 프로세스를 모니터링하고 다양한 상태에 반응하기 위해 이벤트를 듣기하려면 addListener 메소드를 사용하세요. CapacitorUpdater 객체:

import { CapacitorUpdater } from '@capgo/capacitor-updater';
// Add a listener
const listener = await CapacitorUpdater.addListener('eventName', (event) => {
// Handle the event
});
// Remove the listener when no longer needed
listener.remove();
// Remove all listeners
await CapacitorUpdater.removeAllListeners();

사용 가능한 이벤트

사용 가능한 이벤트

download

다운로드

다운로드 프로세스 중에 발생합니다. 다운로드 진행 정보를 제공합니다.

CapacitorUpdater.addListener('download', (event) => {
console.log(`Download progress: ${event.percent}%`);
console.log('Bundle info:', event.bundle);
});

이벤트 데이터:

  • percent: 다운로드 진행률(0-100)
  • bundle: 다운로드 중인 번들 정보

업데이트 확인 시 업데이트가 필요하지 않음을 결정할 때 발생합니다.

CapacitorUpdater.addListener('noNeedUpdate', (event) => {
console.log('App is up to date');
console.log('Current bundle:', event.bundle);
});

이벤트 데이터:

  • bundle: BundleInfo - 현재 버전의 정보

복사

CapacitorUpdater.addListener('updateAvailable', (event) => {
console.log('Update available');
console.log('New bundle:', event.bundle);
// You can trigger a download here if needed
});

: BundleInfo - 다운로드 가능한 업데이트 버전의 정보

  • bundle다운로드가 성공적으로 완료되었을 때 발생하는 이벤트

downloadComplete

복사

이벤트 데이터:

CapacitorUpdater.addListener('downloadComplete', (event) => {
console.log('Download completed');
console.log('Downloaded bundle:', event.bundle);
// You might want to set this bundle as next
});

다운로드가 성공적으로 완료되었을 때 발생하는 이벤트

  • bundle: BundleInfo - 다운로드 된 패키지에 대한 정보

majorAvailable

majorAvailable

major 업데이트가 사용자 설정의 자동 업데이트 차단으로 인해 사용할 수 없습니다.

CapacitorUpdater.addListener('majorAvailable', (event) => {
console.log('Major update available:', event.version);
// Notify user about major update
});

이벤트 데이터:

  • version: string - major 업데이트의 버전 번호

updateFailed

updateFailed

업데이트가 다음 앱 시작 시 설치에 실패했습니다.

CapacitorUpdater.addListener('updateFailed', (event) => {
console.error('Update failed to install');
console.log('Failed bundle:', event.bundle);
// Handle rollback or retry logic
});

이벤트 데이터:

  • bundle: BundleInfo - 설치에 실패한 패키지에 대한 정보

downloadFailed

다운로드 실패

다운로드 실패 시 발생하는 이벤트

CapacitorUpdater.addListener('downloadFailed', (event) => {
console.error('Download failed for version:', event.version);
// Handle download retry logic
});

이벤트 데이터:

  • version: string - 다운로드에 실패한 버전

appReloaded

앱 리로드

앱이 리로드되었습니다.

CapacitorUpdater.addListener('appReloaded', () => {
console.log('App has been reloaded');
// Perform any necessary reinitialization
});

없음 이벤트 데이터:

업데이트 후 앱이 사용할 준비가 되었을 때 발생하는 이벤트입니다.

CapacitorUpdater.addListener('appReady', (event) => {
console.log('App is ready');
console.log('Current bundle:', event.bundle);
console.log('Status:', event.status);
});

이벤트 데이터:

  • bundle: BundleInfo - 현재 배포본에 대한 정보
  • status: string - 준비 상태

Section titled “BundleInfo Object”

Event Data:

많은 이벤트는 다음 속성을 가진 객체를 포함합니다. BundleInfo 속성을 복사하세요

interface BundleInfo {
id: string; // Unique bundle identifier
version: string; // Bundle version
downloaded: string; // Download timestamp
checksum?: string; // Bundle checksum (if available)
status: BundleStatus; // Bundle status
}

가능합니다: BundleStatus - 성공적으로 패키지를 다운로드했습니다

  • 'success' - 패키지 다운로드/설치가 실패했습니다
  • 'error' - 현재 다음으로 설정될 패키지가 대기 중입니다
  • 'pending' - 현재 패키지를 다운로드 중입니다
  • 'downloading' 예시: 업데이트 완료 흐름

이벤트를 사용하여 업데이트 완료 흐름을 처리하는 예시입니다.

import { CapacitorUpdater } from '@capgo/capacitor-updater';
export class UpdateManager {
private listeners: any[] = [];
async setupListeners() {
// Listen for available updates
this.listeners.push(
await CapacitorUpdater.addListener('updateAvailable', async (event) => {
console.log('Update available:', event.bundle.version);
// Auto-download the update
await CapacitorUpdater.download({
url: event.bundle.url,
version: event.bundle.version
});
})
);
// Monitor download progress
this.listeners.push(
await CapacitorUpdater.addListener('download', (event) => {
console.log(`Downloading: ${event.percent}%`);
// Update UI progress bar
this.updateProgressBar(event.percent);
})
);
// Handle download completion
this.listeners.push(
await CapacitorUpdater.addListener('downloadComplete', async (event) => {
console.log('Download complete:', event.bundle.version);
// Set as next bundle
await CapacitorUpdater.next({ id: event.bundle.id });
})
);
// Handle failures
this.listeners.push(
await CapacitorUpdater.addListener('downloadFailed', (event) => {
console.error('Download failed:', event.version);
this.showError('Update download failed. Please try again later.');
})
);
this.listeners.push(
await CapacitorUpdater.addListener('updateFailed', (event) => {
console.error('Update installation failed:', event.bundle.version);
this.showError('Update installation failed. The app has been rolled back.');
})
);
// Handle app ready
this.listeners.push(
await CapacitorUpdater.addListener('appReady', async (event) => {
console.log('App ready with bundle:', event.bundle.version);
})
);
}
cleanup() {
// Remove all listeners when no longer needed
this.listeners.forEach(listener => listener.remove());
this.listeners = [];
}
private updateProgressBar(percent: number) {
// Update your UI progress bar
}
private showError(message: string) {
// Show error to user
}
}

자동 업데이트 흐름을 위해 필요한

자동 업데이트 흐름을 위해 필요한
  1. 자동 업데이트 흐름을 위해 필요한 notifyAppReady()자동 업데이트 흐름을 위해 필요한

  2. 실패를 잘 처리하세요: 다운로드 및 업데이트 실패 시 적절한 오류 처리를 수행하세요.

  3. 사용자에게 피드백을 제공하세요: 다운로드 진행 이벤트를 사용하여 사용자에게 업데이트 진행 상황을 표시하세요.

  4. 리스너를 정리하세요: 더 이상 필요하지 않은 이벤트 리스너를 제거하여 메모리 누수를 방지하세요.

  5. 업데이트 시나리오를 테스트하세요: 실패, 롤백 및 주요 업데이트와 같은 다양한 업데이트 시나리오를 테스트하세요.

다음으로 계속하세요

‘Events’라는 제목을 가진 섹션

만약에 Events 자연 플러그인 작업을 계획하기 위해, 그것을 연결하세요. Using @capgo/capacitor-업데이터 자연 기능을 위한 Using @capgo/capacitor-업데이터 Capgo 플러그인 디렉토리 for the product workflow in Capgo Plugin Directory, Capacitor 플러그인들에 의해 Capgo 자연 플러그인들에 의해 Capacitor 플러그인들에 의해 Capgo 플러그인을 추가하거나 업데이트 플러그인을 추가하거나 업데이트, 그리고 아이오닉 엔터프라이즈 플러그인 대안 아이오닉 엔터프라이즈 플러그인 대안.