メインコンテンツへスキップ

スタートガイド

GitHub

AIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:

ターミナル
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-app-intents` plugin in my project.

手動でセットアップする場合は、パッケージをインストールしてネイティブプロジェクトをsyncしてください:

ターミナル
npm install @capgo/capacitor-app-intents
npx cap sync
import {
CapgoAppIntents,
drainPendingInvocations,
useAppIntentsListener,
} from '@capgo/capacitor-app-intents';

呼び出しの処理(コールドスタート対応)

セクション「呼び出しの処理(コールドスタート対応)」

保留キューを処理する前にリスナーを登録してください。これにより、WebView の起動中に発火した Siri、Shortcuts、Spotlight、クイックアクションが失われるのを防げます。

const handleInvocation = async (invocation) => {
console.log(invocation.name, invocation.params, invocation.source);
};
await useAppIntentsListener(handleInvocation);

useAppIntentsListener をアタッチします appIntentInvoked その後、保留中のアイテムを処理します。また、 getPendingInvocations() と removePendingInvocation() 明示的な制御を好む場合は手動で行えます。

AppShortcut フレーズとSF Symbol名は Swiftのコンパイル時リテラル である必要があります。設定は app-shortcuts.config.json アプリのリポジトリで行い、SwiftをiOS アプリ ターゲットに生成します:

ターミナル
node node_modules/@capgo/capacitor-app-intents/scripts/generate-app-shortcuts.mjs \
--config app-shortcuts.config.json \
--output ios/App/App/CapgoGeneratedAppShortcuts.swift

プラグインのSPMパッケージをアプリターゲットにリンクして、 CapgoDispatchAppIntent resolves. Capacitor 8 では、SceneDelegate のクイックアクションと継続中の Spotlight アクティビティを以下で転送します CapgoAppIntentsLifecycle (プラグインのリポジトリを参照) docs/ios-scene-integration.md).

plugins: {
CapgoAppIntents: {
appGroupId: 'group.your.app',
spotlightDomainIdentifier: 'your.app.bundle',
},
},

JavaScriptの準備ができる前にキューに溜まった呼び出しを返します。

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
const result = await CapgoAppIntents.getPendingInvocations();
console.log(result);

ハンドラーでの処理完了後、保留中の呼び出しを1つ削除します。

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removePendingInvocation({ id: 'id-123' });

指定された型文字列のエンティティカタログを永続化します。

行ごとに新しいSwiftを書くことなく、SiriとShortcutsのエンティティパラメータを駆動します。

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setEntityCatalog({
type: 'type',
entries: [
{
id: 'id-123',
title: 'Hello from Capacitor',
},
],
});

ホーム画面のクイックアクション (UIApplicationShortcutItems) を置き換えます。

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setHomeScreenShortcutItems({
items: [
{
type: 'type',
title: 'Hello from Capacitor',
},
],
});

アプリのドメインのSpotlightアイテムをインデックスします。

〜を使用します CSSearchableItem iOS 16以降で利用可能です。iOS 18以降では、ドネーションもサポートされます。 IndexedEntity 値を通じて indexAppEntities と associateAppEntity.

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.indexSpotlightEntities({
entities: [
{
id: 'id-123',
title: 'Hello from Capacitor',
actionName: 'action',
},
],
});

Spotlightの項目をIDで削除します。

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removeSpotlightEntities({ ids: ['ids'] });

アルファ版のAppleスキーマテンプレート用のJavaScriptハンドラーをキューに追加します。

これはプライベートなMailやシステムスキーマAPIを呼び出すものではありません。単に呼び出しを キューに追加するだけです(例: appleSchemaMailCreateDraft)。これをアプリ code が処理します。

import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
const result = await CapgoAppIntents.performAppleSchemaTemplate({
template: 'mail_create_draft',
params: {},
});
console.log(result);

JavaScriptを待機中の保留中のApp Intentスタイルの呼び出し。

export interface AppIntentInvocation {
/**
* Stable id for this queued invocation.
*
* @since 0.1.0
*/
id: string;
/**
* Handler name your JavaScript listens for.
*
* @since 0.1.0
*/
name: string;
/**
* Parameters passed from Siri, Shortcuts, Spotlight, or quick actions.
*
* @since 0.1.0
*/
params: Record<string, unknown>;
/**
* Origin of the invocation.
*
* @since 0.1.0
*/
source: AppIntentInvocationSource;
/**
* Unix timestamp in milliseconds when the invocation was queued.
*
* @since 0.1.0
*/
createdAt: number;
}

SiriとShortcutsのパラメータで使用されるランタイムエンティティカタログの1行。

export interface EntityCatalogEntry {
/**
* Unique id within the catalog type.
*
* @since 0.1.0
*/
id: string;
/**
* Primary label shown in Shortcuts and Siri.
*
* @since 0.1.0
*/
title: string;
/**
* Optional subtitle.
*
* @since 0.1.0
*/
subtitle?: string;
/**
* Optional extra metadata forwarded to JavaScript when the entity is chosen.
*
* @since 0.1.0
*/
metadata?: Record<string, unknown>;
}

ホーム画面のクイックアクション項目。

export interface HomeScreenShortcutItem {
/**
* Stable type string delivered to JavaScript.
*
* @since 0.1.0
*/
type: string;
/**
* Visible title under the icon.
*
* @since 0.1.0
*/
title: string;
/**
* Optional subtitle.
*
* @since 0.1.0
*/
subtitle?: string;
/**
* Optional SF Symbol name.
*
* @since 0.1.0
*/
iconName?: string;
/**
* Optional params merged into the invocation.
*
* @since 0.1.0
*/
params?: Record<string, unknown>;
}

Spotlightで検索可能なエンティティ。

export interface SpotlightEntity {
/**
* Unique id within your app domain.
*
* @since 0.1.0
*/
id: string;
/**
* Title shown in Spotlight.
*
* @since 0.1.0
*/
title: string;
/**
* Optional description.
*
* @since 0.1.0
*/
description?: string;
/**
* Optional keywords.
*
* @since 0.1.0
*/
keywords?: string[];
/**
* Action name delivered when the result is opened.
*
* @since 0.1.0
*/
actionName: string;
/**
* Optional params merged into the invocation.
*
* @since 0.1.0
*/
params?: Record<string, unknown>;
}

プラグインが提供するアルファ版のApple schema template識別子。

export type AppleSchemaTemplate = 'mail_create_draft';
export interface AppIntentInvokedEvent {
/**
* The invocation that was just queued or replayed to listeners.
*
* @since 0.1.0
*/
invocation: AppIntentInvocation;
}

呼び出しの発生元。

export type AppIntentInvocationSource = 'app_intent' | 'spotlight' | 'quick_action' | 'apple_schema';

このページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。