Guide
Comment utiliser les App Intents dans Capacitor
Utiliser @capgo/capacitor-app-intents
Interface du plugin App Intents pour Capgo.
Installer
bun add @capgo/capacitor-app-intents
bunx cap sync
bunx cap sync copie le code natif du plugin dans vos projets natifs. Relancez-l’après chaque mise à jour du plugin.
Importer
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
Aperçu de API
| Méthode | Description |
|---|---|
getPendingInvocations |
Return invocations queued before JavaScript was ready. |
removePendingInvocation |
Supprime une invocation en attente après que votre gestionnaire l’a traitée. |
setEntityCatalog |
Persistez un catalogue d'entités pour une chaîne de type donnée. |
setHomeScreenShortcutItems |
Remplacez les actions rapides de l'écran d'accueil (UIApplicationShortcutItems). |
indexSpotlightEntities |
Indexez les éléments Spotlight pour le domaine de votre app. |
removeSpotlightEntities |
Supprime les éléments Spotlight par identifiant. |
performAppleSchemaTemplate |
Mettre en file d’attente un handler JavaScript pour un modèle de schéma Apple alpha. |
Exemples
getPendingInvocations()
Return invocations queued before JavaScript was ready.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
const result = await CapgoAppIntents.getPendingInvocations();
console.log(result);
removePendingInvocation()
Supprime une invocation en attente après que votre gestionnaire l’a traitée.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removePendingInvocation({ id: 'id-123' });
setEntityCatalog()
Persistez un catalogue d'entités pour une chaîne de type donnée.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setEntityCatalog({
type: 'type',
entries: [
{
id: 'id-123',
title: 'Hello from Capacitor',
},
],
});
setHomeScreenShortcutItems()
Remplacez les actions rapides de l'écran d'accueil (UIApplicationShortcutItems).
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.setHomeScreenShortcutItems({
items: [
{
type: 'type',
title: 'Hello from Capacitor',
},
],
});
indexSpotlightEntities()
Indexez les éléments Spotlight pour le domaine de votre app.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.indexSpotlightEntities({
entities: [
{
id: 'id-123',
title: 'Hello from Capacitor',
actionName: 'action',
},
],
});
removeSpotlightEntities()
Supprime les éléments Spotlight par identifiant.
import { CapgoAppIntents } from '@capgo/capacitor-app-intents';
await CapgoAppIntents.removeSpotlightEntities({ ids: ['ids'] });
Le tableau ci-dessus liste les 7 méthodes principales. Les listeners, les helpers de version et le contrat complet de chaque méthode sont documentés dans la dépôt GitHub.
Écouter les événements
addListener renvoie un handle. Appelez handle.remove() lors du démontage de l'écran, ou CapgoAppIntents.removeAllListeners() pour supprimer tous les listeners.