Zum Inhalt springen

Erste Schritte

GitHub

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:

Terminalfenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Nutze 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:

Terminalfenster
bun add @capgo/capacitor-downloader
bunx cap sync
import { CapacitorDownloader } from '@capgo/capacitor-downloader';

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',
});
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 });
  • Storage destination: wähle ein destination deine 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 checkStatus solange der App-Prozess noch läuft. Unter iOS werden Task-IDs nach einem Relaunch nicht wiederhergestellt.

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'
});

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' });

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' });

Den aktuellen Status eines Downloads prüfen.

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

Informationen zu einer heruntergeladenen Datei abrufen.

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

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';
}

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';
}

Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.

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.