Erste Schritte
Kopiere einen Setup-Prompt mit den Installationsschritten und dem vollständigen Markdown-Guide für dieses Plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-downloader`
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/downloader/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.
Installieren
Abschnitt „Installation“Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsNutze dann diesen Prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-downloader` plugin in my project.Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:
bun add @capgo/capacitor-downloaderbunx cap syncImportieren
Abschnitt mit dem Titel „Import“import { CapacitorDownloader } from '@capgo/capacitor-downloader';Quickstart
Abschnitt „Quick start“In einen bekannten Ordner herunterladen, Fortschritt verfolgen und – wenn unterstützt – nach einem App-Neustart fortsetzen.
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',});Beispiel: Pausieren und Fortsetzen
Abschnitt mit dem Titel „Beispiel: Pausieren und Fortsetzen“await CapacitorDownloader.pause({ id: 'offline-pack' });await CapacitorDownloader.resume({ id: 'offline-pack' });Beispiel: Fertige Datei prüfen
Abschnitt mit dem Titel „Beispiel: Fertige Datei prüfen“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 });Häufige Stolperfallen
Abschnitt „Häufige Fallstricke“- Storage destination: wähle ein
destinationdeine App auf jeder Plattform lesen kann. - Hintergrund: Downloads laufen auf iOS und Android im Hintergrund. Im Web
download()ist nicht implementiert; nutze stattdessen den Browser-Download-Flow. - Status: nutzen
checkStatussolange der App-Prozess noch läuft. Unter iOS werden Task-IDs nach einem Relaunch nicht wiederhergestellt.
API Übersicht
Abschnitt „API Übersicht“download
Abschnitt „download“Einen neuen Download-Task starten.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await CapacitorDownloader.download({ id: 'my-download', url: 'https://example.com/file.pdf', destination: 'downloads/file.pdf'});pause
Abschnitt „pause“Einen aktiven Download pausieren. Der Download kann später an derselben Stelle fortgesetzt werden.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({ id: 'id-123' });resume
Abschnitt „resume“Einen pausierten Download fortsetzen. Fährt dort fort, wo er unterbrochen wurde.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({ id: 'id-123' });Einen Download stoppen und dauerhaft abbrechen. Die heruntergeladenen Daten werden gelöscht.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({ id: 'id-123' });checkStatus
Abschnitt mit dem Titel „checkStatus“Den aktuellen Status eines Downloads prüfen.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.checkStatus({ id: 'id-123' });console.log(result);getFileInfo
Abschnitt mit dem Titel „getFileInfo“Informationen zu einer heruntergeladenen Datei abrufen.
import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const result = await CapacitorDownloader.getFileInfo({ path: 'path/to/file' });console.log(result);Typreferenz
Abschnitt mit dem Titel „Typreferenz“DownloadOptions
Abschnitt mit dem Titel „DownloadOptions“Konfigurationsoptionen zum Starten eines Downloads.
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';}DownloadTask
Abschnitt mit dem Titel „DownloadTask“Repräsentiert den aktuellen Status und Fortschritt eines Download-Tasks.
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';}Source of Truth
Abschnitt mit dem Titel „Source of Truth“Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.
Weiter geht's nach Getting Started
Abschnitt: „Weiter geht’s mit Getting Started“Wenn du es nutzt Erste Schritte um Dashboard- und API-Operationen zu planen, verbinde es mit Nutzung von @capgo/capacitor-downloader für die native Funktion in der Nutzung von @capgo/capacitor-downloader, API Übersicht für Details zur Implementierung im API Overview, Einführung für die Implementierungsdetails in der Einleitung, API Schlüssel für das Implementierungsdetail in API Keys und Geräte für das Implementierungsdetail in Devices.