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ählen destination Ihre App auf jeder Plattform lesen kann.
  • Hintergrund: Downloads werden auf iOS und Android im Hintergrund ausgeführt. Auf Web download() ist nicht implementiert; stattdessen einen Browser-Download-Flow verwenden.
  • Status: verwenden checkStatus solange der App-Prozess noch aktiv ist. Auf iOS werden Task-IDs nach einem Neustart nicht wiederhergestellt.

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

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

Pausierten Download fortsetzen. Fährt dort fort, wo er pausiert wurde.

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

Download dauerhaft stoppen und abbrechen. Die heruntergeladenen Daten werden gelöscht.

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

Aktuellen Status eines Downloads abrufen.

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 für den Start 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';
}

Stellt den aktuellen Status und den Fortschritt einer Download-Aufgabe dar.

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 Mit @capgo/capacitor-downloader für die native Funktion bei 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.