Getting Started
이 플러그인의 설치 단계와 전체 마크다운 가이드를 포함한 설정 지시서를 복사하세요.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-background-task`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/background-task/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
@capgo/capacitor-background-task Capacitor 앱은 동기화, 캐시 갱신, 분석 데이터 전송 및 기타 백그라운드 가져오기 작업을 위한 주기적인 작업을 등록할 수 있습니다.
설치
설치npm install @capgo/capacitor-background-tasknpx cap synciOS 설정
iOS 설정배경 처리 모드를 추가하고 허용된 작업 식별자를 ios/App/App/Info.plist:
<key>UIBackgroundModes</key><array> <string>processing</string></array><key>BGTaskSchedulerPermittedIdentifiers</key><array> <string>app.capgo.backgroundtask.processing</string></array>그런 다음 실행하십시오:
npx cap sync iosImport
Import 섹션import { BackgroundTask, BackgroundTaskResult } from '@capgo/capacitor-background-task';작업 정의
작업 정의 섹션앱이 운영 체제에 의해 시작되면 즉시 등록되도록 모듈 스코프에서 콜백을 정의하세요.
import { BackgroundTask, BackgroundTaskResult } from '@capgo/capacitor-background-task';
const SYNC_TASK = 'sync-offline-data';
BackgroundTask.defineTask(SYNC_TASK, async () => { try { await fetch('https://api.example.com/sync', { method: 'POST' }); return BackgroundTaskResult.Success; } catch { return BackgroundTaskResult.Failed; }});스케줄 등록
스케줄 등록 섹션앱이 충분한 컨텍스트를 갖고 배경 작업을 활성화할 수 있을 때 호출하세요. registerTaskAsync 클립보드 복사
await BackgroundTask.registerTaskAsync(SYNC_TASK, { minimumInterval: 30, requiresNetwork: true,});minimumInterval __CAPGO_KEEP_0__. 분 이내입니다. Android는 최소 15분을 강제로 적용합니다. iOS는 값을 가장 빠른 시작 날짜로 인식하고 더 늦게 실행할 수 있습니다.
const status = await BackgroundTask.getStatusAsync();const isRegistered = await BackgroundTask.isTaskRegisteredAsync(SYNC_TASK);const registeredTasks = await BackgroundTask.getRegisteredTasksAsync();
console.log({ status, isRegistered, registeredTasks });복사
await BackgroundTask.triggerTaskWorkerForTestingAsync();__CAPGO_KEEP_0__.
복사await BackgroundTask.unregisterTaskAsync(SYNC_TASK);__CAPGO_KEEP_0__
iOS 만료iOS는 JavaScript 작업이 완료되기 전에 백그라운드 작업을 중단할 수 있습니다. cleanup 또는 checkpointing이 필요한 경우 만료 이벤트를 듣는 것이 좋습니다.
const expiration = await BackgroundTask.addExpirationListener((event) => { console.warn('Background task expired', event.taskName, event.taskId);});
await expiration.remove();React Native 백그라운드 작업 호환성
The plugin also exposes a small compatibility layer for apps migrating from클립보드에 복사 react-native-background-task.
import { BackgroundTask } from '@capgo/capacitor-background-task';
BackgroundTask.define(async () => { await fetch('https://api.example.com/sync', { method: 'POST' });});
await BackgroundTask.schedule({ period: 1800,});백그라운드 스케줄링은 정확하지 않습니다.
작업을 짧고 idempotent하게 유지하세요.- The plugin also exposes a small compatibility layer for apps migrating from React Native to Capacitor.
- 클립보드에 복사
- 필요한 모든 상태를 유지하기 위해 반환하기 전에
BackgroundTaskResult.Success. - 사용자에게 보이는 마감일이나 알람을 위해 배경 작업에 의존하지 마세요.
Getting Started에서 계속하기
Getting Started에서 계속하기란?Capacitor를 사용하고 있다면 Getting Started Capacitor를 사용하여 네이티브 플러그인 작업을 계획할 때, 그것을 Using @capgo/capacitor-background-task Using @capgo/capacitor-background-task에서 사용하는 네이티브 기능에 대해 Capgo Plugin Directory Capgo Plugin Directory에서 사용하는 제품 워크플로우에 대해 Capacitor Plugins by Capgo Capacitor 플러그인에 대한 구현 세부 정보는 Capgo에서 확인할 수 있습니다. 플러그인 추가 또는 업데이트 __CAPGO_KEEP_0__ 플러그인에 대한 구현 세부 정보는 플러그인 추가 또는 업데이트, 및 Ionic Enterprise 플러그인 대체 __CAPGO_KEEP_0__ 제품 워크플로우는 Ionic Enterprise 플러그인 대체입니다.