コンテンツにジャンプ

Getting Started

ターミナル画面
bun add @capgo/capacitor-share-target
bunx cap sync
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

shareReceived イベントをリスンする

他のアプリからアプリケーションにコンテンツが共有されたときに呼び出されるリスナを登録します。コールバックは、タイトル、テキスト、ファイルを含むイベントデータを受け取ります。

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

このプラグインのすべてのリスナーを削除します。

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

ネイティブ Capacitor プラグインのバージョンを取得します。

Returns the current version of the native plugin implementation.

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

アプリケーションにコンテンツが共有されたときに受信されるイベントデータ。

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

アプリケーションに共有されたファイルを表します。

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

プラグインの src/definitions.tsパブリック API がアップストリームで変更された場合に再度同期を実行してください。

Capgo を使用している場合 Getting Started ダッシュボードと API の作業を計画するには、接続してください。 Capgoの@capgo/capacitor-share-targetを使用 Capgoの@capgo/capacitor-share-targetのnative capabilityを使用 APIの概要 APIの実装詳細 導入 __CAPGO_KEEP_0__のキー APIの実装詳細 for the implementation detail in API Keys, and 編集 前のページ