Anleitung
App Intents in Capacitor nutzen
Verwendung von @capgo/capacitor-app-intents
Capgo App Intents Plugin-Interface.
Installieren
bun add @capgo/capacitor-app-intents
bunx cap sync
bunx cap sync kopiert den nativen code des Plugins in deine nativen Projekte. Nach jedem Plugin-Upgrade erneut ausführen.
Importieren
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
API auf einen Blick
| Methode | Beschreibung |
|---|---|
getPendingInvocations |
Gibt Aufrufe zurück, die eingereiht wurden, bevor JavaScript bereit war. |
removePendingInvocation |
Entferne eine ausstehende Invokation, nachdem dein Handler sie verarbeitet hat. |
setEntityCatalog |
Speichert einen Entity-Katalog dauerhaft für einen bestimmten Typ-String. |
setHomeScreenShortcutItems |
Ersetzt Home Screen Quick Actions (UIApplicationShortcutItems). |
indexSpotlightEntities |
Indiziert Spotlight-Items für deine App-Domain. |
removeSpotlightEntities |
Spotlight-Elemente anhand der ID entfernen. |
performAppleSchemaTemplate |
Einen JavaScript-Handler für ein Alpha-Apple-Schema-Template in die Warteschlange stellen. |
Beispiele
getPendingInvocations()
Gibt Aufrufe zurück, die eingereiht wurden, bevor JavaScript bereit war.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
const result = await CapgoAppIntents.getPendingInvocations();
console.log(result);
removePendingInvocation()
Nach der Verarbeitung durch deinen Handler wird ein ausstehender Aufruf entfernt.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removePendingInvocation({ id: 'id-123' });
setEntityCatalog()
Speichert einen Entity-Katalog dauerhaft für einen bestimmten Typ-String.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setEntityCatalog({
type: 'type',
entries: [
{
id: 'id-123',
title: 'Hello from Capacitor',
},
],
});
setHomeScreenShortcutItems()
Ersetzt Home Screen Quick Actions (UIApplicationShortcutItems).
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setHomeScreenShortcutItems({
items: [
{
type: 'type',
title: 'Hello from Capacitor',
},
],
});
indexSpotlightEntities()
Indiziert Spotlight-Items für deine App-Domain.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.indexSpotlightEntities({
entities: [
{
id: 'id-123',
title: 'Hello from Capacitor',
actionName: 'action',
},
],
});
removeSpotlightEntities()
Spotlight-Elemente anhand der ID entfernen.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removeSpotlightEntities({ ids: ['ids'] });
Die obige Tabelle listet die 7 Kernmethoden auf. Listener, Version-Helper und der vollständige Contract jeder Methode sind in der GitHub Repository.
Events abonnieren
addListener gibt ein Handle zurück. Rufe handle.remove() auf, wenn der Screen unmountet, oder CapgoAppIntents.removeAllListeners() auf, um alle Listener zu entfernen.