はじめに
このプラグインのインストール手順とMarkdownガイド全文を含む、セットアップ用プロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-share-target`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/share-target/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「Install」セクションAIアシストセットアップを使用してプラグインをインストールできます。次のコマンドを使用して、Capgo のスキルをAIツールに追加してください:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用してください:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-share-target` plugin in my project.手動でのセットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、各プラットフォームごとの手順に従ってください:
bun add @capgo/capacitor-share-targetbunx cap syncインポート
「Import」セクションimport { CapacitorShareTarget } from '@capgo/capacitor-share-target';早期リスニング (コールドスタート)
「Listen early (cold start)」セクション登録 shareReceived アプリの起動直後、共有コンテンツを消費する画面へユーザーをルーティングする前に実行してください。iOSでは、JavaScriptがイベントを消費するまでネイティブレイヤーがイベントを保持するため、WebViewの起動中に届いたシェアもカバーできます。
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
const shareListener = await CapacitorShareTarget.addListener('shareReceived', (event) => { routeSharedPayload(event.title, event.texts, event.files);});
// When tearing down the handler:await shareListener.remove();設定 appGroupId で capacitor.config および、Share Extensionでも同じApp Groupをミラーリングしてください。拡張機能のサンプル code については、GitHub のプラグインREADMEを参照してください。
よくある落とし穴
「よくある落とし穴」というタイトルのセクション- ネイティブ設定: intentはREADMEにあるmanifestとXcodeの設定完了後にのみ動作します。
- コールドスタート: ルーターの準備ができるまで共有をバッファリングします。
- File URI: upload前にアプリのストレージにコピーしてください。アクセス権が失効する場合があります。
API の概要
「API 概要」セクションaddListener
「addListener」セクションshareReceived イベントをリッスンします。
他のアプリからアプリへコンテンツが共有された際に呼び出されるリスナーを登録します。コールバックでは、title、texts、files を含むイベントデータを受け取ります。
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();removeAllListeners
「removeAllListeners」セクションこのプラグインのすべてのリスナーを削除します。
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
await CapacitorShareTarget.removeAllListeners();getPluginVersion
「getPluginVersion」セクションネイティブの Capacitor プラグインのバージョンを取得します。
ネイティブプラグイン実装の現在のバージョンを返します。
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';
const { version} = await CapacitorShareTarget.getPluginVersion();console.log('Plugin version:', version);型リファレンス
「型リファレンス」というタイトルのセクションShareReceivedEvent
「ShareReceivedEvent」というタイトルのセクションコンテンツがアプリケーションに共有された際に受信するイベントデータ。
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[];}SharedFile
「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;}信頼できる情報源 (Source of Truth)
「Source Of Truth」というタイトルのセクションこのページはプラグインの src/definitions.ts から生成されています。アップストリームの公開 API が変更された場合は、再度同期を実行してください。
Getting Started から次へ
「Getting Started から次へ」というタイトルのセクション以下を使用している場合: はじめに ダッシュボードや API の運用を計画するには、これと連携させてください @capgo/capacitor-share-target を使用する Using @capgo/capacitor-share-target のネイティブ機能については、 API の概要 API Overview の実装詳細については、 はじめに Introduction の実装詳細については、 API キー API Keys の実装詳細については、 デバイス Devices の実装詳細については、