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 앱이 등록된 주기적인 작업, 캐시 갱신, 분석 데이터 전송, 및 다른 배경 가져오기 작업을 위해 이름을 사용할 수 있습니다.
설치
설치설치하기 위해 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 iosimport { 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 __CAPGO_KEEP_0__
await BackgroundTask.registerTaskAsync(SYNC_TASK, { minimumInterval: 30, requiresNetwork: true,});minimumInterval __CAPGO_KEEP_2__
__CAPGO_KEEP_3__
__CAPGO_KEEP_4__const status = await BackgroundTask.getStatusAsync();const isRegistered = await BackgroundTask.isTaskRegisteredAsync(SYNC_TASK);const registeredTasks = await BackgroundTask.getRegisteredTasksAsync();
console.log({ status, isRegistered, registeredTasks });__CAPGO_KEEP_6__
__CAPGO_KEEP_7____CAPGO_KEEP_8__
await BackgroundTask.triggerTaskWorkerForTestingAsync();__CAPGO_KEEP_10__
__CAPGO_KEEP_11__await BackgroundTask.unregisterTaskAsync(SYNC_TASK);iOS 만료
iOS ExpirationiOS는 JavaScript 작업이 끝나기 전에 백그라운드 작업을 중단할 수 있습니다. cleanup 또는 checkpointing이 중요할 때는 만료 이벤트를 듣는 것이 좋습니다.
const expiration = await BackgroundTask.addExpirationListener((event) => { console.warn('Background task expired', event.taskName, event.taskId);});
await expiration.remove();React Native 백그라운드 작업 호환성
React Native Background Task Compatibility이 플러그인은 React Native 앱이 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,});제작 노트
Production Notes- 배경 스케줄링은 정확하지 않습니다.
- 작업을 짧고 idempotent하게 유지하세요.
- 필요한 모든 상태를 반환하기 전에 저장하세요.
BackgroundTaskResult.Success. - 사용자에게 보이는 deadline이나 alarm에 의존하지 마세요.
Getting Started에서 계속하세요.
Getting Started에서 계속하세요.__CAPGO_KEEP_0__을 사용하고 있다면 Getting Started에서 native plugin 작업을 계획하기 위해 연결하세요. capgo/capacitor-background-task를 사용하여 @capgo/capacitor-background-task for the native capability in Using @capgo/capacitor-background-task, Capgo Plugin Directory를 사용하여 제품 워크플로우를 관리하세요. for the product workflow in Capgo Plugin Directory, Capacitor 플러그인들에 의해 Capgo Capacitor 플러그인들에 의해 Capgo의 구현 세부 정보를 위해 플러그인 추가 또는 업데이트 플러그인 추가 또는 업데이트의 구현 세부 정보를 위해, 아이오닉 엔터프라이즈 플러그인 대체 아이오닉 엔터프라이즈 플러그인 대체의 제품 워크플로에 대해