ガイド
Capacitor で App Intents を使う方法
@capgo/capacitor-app-intents の使用
Capgo App Intents プラグインのインターフェース。
インストール
bun add @capgo/capacitor-app-intents
bunx cap sync
bunx cap sync プラグインのネイティブcodeをネイティブプロジェクトにコピーします。プラグインをアップグレードするたびに再度実行してください。
インポート
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
API の概要
| メソッド | 説明 |
|---|---|
getPendingInvocations |
JavaScriptの準備ができる前にキューに溜まった呼び出しを返します。 |
removePendingInvocation |
ハンドラーでの処理完了後、保留中の呼び出しを1つ削除します。 |
setEntityCatalog |
指定された型文字列のエンティティカタログを永続化します。 |
setHomeScreenShortcutItems |
ホーム画面のクイックアクション (UIApplicationShortcutItems) を置き換えます。 |
indexSpotlightEntities |
アプリのドメインのSpotlightアイテムをインデックスします。 |
removeSpotlightEntities |
Spotlightの項目をIDで削除します。 |
performAppleSchemaTemplate |
アルファ版のAppleスキーマテンプレート用のJavaScriptハンドラーをキューに追加します。 |
例
getPendingInvocations()
JavaScriptの準備ができる前にキューに溜まった呼び出しを返します。
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
const result = await CapgoAppIntents.getPendingInvocations();
console.log(result);
removePendingInvocation()
ハンドラーでの処理完了後、保留中の呼び出しを1つ削除します。
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removePendingInvocation({ id: 'id-123' });
setEntityCatalog()
指定された型文字列のエンティティカタログを永続化します。
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setEntityCatalog({
type: 'type',
entries: [
{
id: 'id-123',
title: 'Hello from Capacitor',
},
],
});
setHomeScreenShortcutItems()
ホーム画面のクイックアクション (UIApplicationShortcutItems) を置き換えます。
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setHomeScreenShortcutItems({
items: [
{
type: 'type',
title: 'Hello from Capacitor',
},
],
});
indexSpotlightEntities()
アプリのドメインのSpotlightアイテムをインデックスします。
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.indexSpotlightEntities({
entities: [
{
id: 'id-123',
title: 'Hello from Capacitor',
actionName: 'action',
},
],
});
removeSpotlightEntities()
Spotlightの項目をIDで削除します。
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removeSpotlightEntities({ ids: ['ids'] });
上記の表には7つの主要なメソッドが記載されています。リスナーやバージョンのヘルパー、および各メソッドの詳細な仕様については、 GitHub リポジトリ.
イベントをリッスンする
addListener ハンドルを返します。画面がアンマウントされるときに handle.remove() 画面がアンマウントされるとき、または CapgoAppIntents.removeAllListeners() すべてのリスナーを解除します。