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을 등록하여 주기적인 작업, 캐시 갱신, 분석 데이터 전송 및 다른 배경 가져오기 작업을 동기화, 캐시 갱신, 분석 데이터 전송 및 다른 배경 가져오기 작업을 동기화합니다.
설치
설치Capgo의 AI-Assisted Setup을 사용하여 플러그인을 설치할 수 있습니다. 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-background-task` plugin in my project.Manual Setup을 선호한다면, 플러그인을 설치하기 위해 다음 명령어를 실행하고 아래의 플랫폼별 지침을 따르세요:
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 ios수입
수입 제목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 분 단위입니다. 안드로이드는 최소 15분을 강제로 적용하고, iOS는 값을 가장 빠른 시작 날짜로 처리하여 나중에 실행할 수 있습니다.
상태 확인
Check Statusconst status = await BackgroundTask.getStatusAsync();const isRegistered = await BackgroundTask.isTaskRegisteredAsync(SYNC_TASK);const registeredTasks = await BackgroundTask.getRegisteredTasksAsync();
console.log({ status, isRegistered, registeredTasks });테스트 실행
Trigger A Test Run개발 또는 QA 환경에서 테스트 트리거를 사용하세요. 이 트리거는 모든 등록된 작업을 즉시 호출합니다.
await BackgroundTask.triggerTaskWorkerForTestingAsync();Task를 해제하세요
Task를 해제하는 방법await BackgroundTask.unregisterTaskAsync(SYNC_TASK);iOS 만료
iOS 만료iOS는 JavaScript 작업이 끝나기 전에 백그라운드 작업을 중단할 수 있습니다. cleanup 또는 checkpointing이 필요한 경우 만료 이벤트를 듣는 것이 좋습니다.
const expiration = await BackgroundTask.addExpirationListener((event) => { console.warn('Background task expired', event.taskName, event.taskId);});
await expiration.remove();리액트 네이티브 백그라운드 작업 호환성
Section titled “리액트 네이티브 백그라운드 작업 호환성”이 플러그인은 앱이 리액트 네이티브에서 Capacitor로 마이그레이션하는 경우에 작은 호환성 layer를 노출합니다. 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 하게 유지하세요.
- 반환하기 전에 필요한 모든 상태를 저장하세요.
BackgroundTaskResult.Success. - 사용자에게 보이는 마감일이나 알람에 의존하지 마세요.
Getting Started로 계속 진행하세요.
이러한 경우Getting Started 자연 플러그인 작업을 계획하는 경우 Using @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-background-task Using @capgo/capacitor-background-task Using @capgo/capacitor-background-task Capgo 플러그인 디렉토리 Capgo 제품 워크플로우를 위한 Capgo 플러그인 디렉토리 Capacitor Capgo 플러그인 Capgo 제품 워크플로우를 위한 Capacitor Capgo 플러그인 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트 구현 세부 사항, 및 아이오닉 엔터프라이즈 플러그인 대안 Capgo 제품 워크플로우를 위한 아이오닉 엔터프라이즈 플러그인 대안