Saltar al contenido

Empezar

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

Escucha el evento shareReceived.

Registra un oyente que se llamará cuando el contenido se comparta en la aplicación de otra aplicación. La función de llamada recibe datos de evento que contienen título, texto y archivos.

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();

Quitar todos los oyentes para este plugin.

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

Obtén la versión nativa Capacitor del plugin.

Devuelve la versión actual del plugin de implementación nativa.

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

Los datos del evento se reciben cuando el contenido se comparte con la aplicación.

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[];
}

Representa un archivo compartido con la aplicación.

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

Esta página se genera a partir del plugin’s. Re-ejecutar la sincronización cuando los cambios públicos __CAPGO_KEEP_0__ se actualicen en la fuente. src/definitions.ts. Re-run the sync when the public API changes upstream.