Aller directement au contenu

Démarrage

Fenêtre de terminal
bun add @capgo/capacitor-share-target
bunx cap sync
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

Écoutez l'événement shareReceived.

Enregistre un écouteur qui sera appelé lorsque du contenu est partagé vers l'application à partir d'une autre application. Le callback reçoit des données d'événement contenant titre, textes et fichiers.

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
const listener = await CapacitorShareTarget.addListener('shareReceived', (event) => {
console.log('Title:', event.title);
console.log('Texts:', event.texts);
event.files?.forEach(file => {
console.log(`File: ${file.name} (${file.mimeType})`);
});
});
// To remove the listener:
await listener.remove();

Supprimer tous les écouteurs pour ce plugin.

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
await CapacitorShareTarget.removeAllListeners();

Obtenez la version native Capacitor du plugin.

Renvoie la version actuelle de la mise en œuvre native du plugin.

import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
const { version} = await CapacitorShareTarget.getPluginVersion();
console.log('Plugin version:', version);

Données d'événement reçues lors de la partage de contenu vers l'application.

export interface ShareReceivedEvent {
/**
* The title of the shared content.
*
* @since 0.1.0
*/
title: string;
/**
* Array of text content shared to the application.
*
* @since 0.1.0
*/
texts: string[];
/**
* Array of files shared to the application.
*
* @since 0.2.0
*/
files: SharedFile[];
}

Représente un fichier partagé vers l'application.

export interface SharedFile {
/**
* The URI of the shared file. On Android/iOS this will be a file path or data URL.
* On web this will be a cached URL accessible via fetch.
*
* @since 0.1.0
*/
uri: string;
/**
* The name of the shared file, with or without extension.
*
* @since 0.1.0
*/
name: string;
/**
* The MIME type of the shared file.
*
* @since 0.1.0
*/
mimeType: string;
}

Cette page est générée à partir du plugin's. Re-run la synchronisation lorsque les données publiques __CAPGO_KEEP_0__ changent en amont. src/definitions.ts. Re-run the sync when the public API changes upstream.