본문 바로가기

시작하기

GitHub

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-downloader` plugin in my project.

수동 설정을 선호한다면, 다음 명령어를 실행하여 플러그인을 설치하고 아래의 플랫폼별 지침을 따르세요:

터미널 창
bun add @capgo/capacitor-downloader
bunx cap sync
import { CapacitorDownloader } from '@capgo/capacitor-downloader';

알려진 폴더로 다운로드하고, 진행 상황을 추적하며, 지원되는 경우 앱 재시작 후 이어서 다운로드합니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const progressListener = await CapacitorDownloader.addListener('downloadProgress', (event) => {
if (event.id === 'offline-pack') {
console.log(event.progress);
}
});
const task = await CapacitorDownloader.download({
id: 'offline-pack',
url: 'https://cdn.example.com/large-pack.zip',
destination: 'downloads/offline-pack.zip',
});
await CapacitorDownloader.pause({ id: 'offline-pack' });
await CapacitorDownloader.resume({ id: 'offline-pack' });
import { Capacitor } from '@capacitor/core';
import { Directory, Filesystem } from '@capacitor/filesystem';
const relativePath = 'downloads/offline-pack.zip';
const path =
Capacitor.getPlatform() === 'ios'
? (await Filesystem.getUri({ directory: Directory.Documents, path: relativePath })).uri
: relativePath;
const info = await CapacitorDownloader.getFileInfo({ path });

자주 하는 실수

“흔한 실수” 섹션
  • 저장 위치: 선택 destination 각 플랫폼에서 앱이 읽을 수 있는
  • 백그라운드: iOS와 Android에서는 백그라운드에서 다운로드가 실행됩니다. Web에서는 download() 구현되어 있지 않으며, 대신 브라우저 다운로드 플로우를 사용하세요.
  • 상태: 사용 checkStatus 앱 프로세스가 살아 있는 동안에만 유효합니다. iOS에서는 앱을 다시 실행해도 task ID가 복원되지 않습니다.

새 다운로드 작업을 시작합니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await CapacitorDownloader.download({
id: 'my-download',
url: 'https://example.com/file.pdf',
destination: 'downloads/file.pdf'
});

진행 중인 다운로드를 일시 중지합니다. 나중에 같은 지점에서 다운로드를 재개할 수 있습니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({ id: 'id-123' });

일시 중지된 다운로드를 재개합니다. 중단된 시점부터 다시 시작합니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({ id: 'id-123' });

다운로드를 중지하고 영구적으로 취소합니다. 다운로드된 데이터는 삭제됩니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({ id: 'id-123' });

다운로드의 현재 상태를 확인합니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.checkStatus({ id: 'id-123' });
console.log(result);

다운로드된 파일에 대한 정보를 가져옵니다.

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.getFileInfo({ path: 'path/to/file' });
console.log(result);

타입 레퍼런스

“타입 참조” 섹션

다운로드를 시작하기 위한 설정 옵션입니다.

export interface DownloadOptions {
/** Unique identifier for this download task */
id: string;
/** URL of the file to download */
url: string;
/** Local file path where the download will be saved */
destination: string;
/** Optional HTTP headers to include in the request */
headers?: { [key: string]: string };
/** Network type requirement for download */
network?: 'cellular' | 'wifi-only';
/** Download priority level */
priority?: 'high' | 'normal' | 'low';
}

다운로드 작업의 현재 상태와 진행률을 나타냅니다.

export interface DownloadTask {
/** Unique identifier for the download task */
id: string;
/** Download progress from 0 to 100 */
progress: number;
/** Current state of the download */
state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';
}

이 페이지는 플러그인의 src/definitions.tsupstream에서 public API가 변경되면 sync를 다시 실행하세요.

사용 중이라면 시작하기 대시보드 및 API 운영을 계획하려면, 이를 다음과 연결하세요 @capgo/capacitor-downloader 사용하기 @capgo/capacitor-downloader 사용 시 네이티브 기능을 위해서는, API 개요 구현 세부 사항은 API 개요에서 소개 구현 세부 사항은 소개에서 API 키 API Keys의 구현 세부 사항은, 기기 Devices의 구현 세부 사항은.