본문 바로가기

시작하기

GitHub

AI 지원 설정으로 플러그인을 설치할 수 있습니다. 다음 명령어로 AI 도구에 Capgo 스킬을 추가하세요:

터미널 창
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

그다음 아래 prompt를 사용하세요:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-share-target` plugin in my project.

Manual Setup을 선호한다면, 다음 명령어를 실행하여 플러그인을 설치하고 아래의 플랫폼별 지침을 따르세요:

터미널 창
bun add @capgo/capacitor-share-target
bunx cap sync
import { CapacitorShareTarget } from '@capgo/capacitor-share-target';

조기 리스닝 (Cold Start)

“조기 리스닝 (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을 설정하세요. Extension 샘플 code은 GitHub의 플러그인 README를 참조하세요.

  • 네이티브 설정: Intent는 README에 명시된 manifest 및 Xcode 설정 단계를 완료해야 작동합니다.
  • 콜드 스타트: 라우터가 준비될 때까지 공유 데이터를 버퍼링합니다.
  • 파일 URI: upload 전 앱 스토리지로 복사해야 하며, 액세스 권한이 만료될 수 있습니다.

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

이 플러그인의 모든 리스너를 제거합니다.

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

네이티브 Capacitor 플러그인 버전을 가져옵니다.

네이티브 플러그인 구현의 현재 버전을 반환합니다.

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에서 생성되었습니다. public API가 업스트림에서 변경되면 동기화를 다시 실행하세요.

사용 중인 경우 시작하기 대시보드와 API 운영을 계획하려면, 이를 다음 항목과 연결하세요: @capgo/capacitor-share-target 사용하기 @capgo/capacitor-share-target를 사용하여 네이티브 기능을 구현할 때, API 개요 API Overview의 구현 상세 내용은 소개 Introduction의 구현 상세 내용은 API 키 API Keys의 구현 세부 사항은, 디바이스 Devices의 구현 세부 사항은.