Zum Inhalt springen

Erste Schritte

GitHub

Du kannst unser KI-gestütztes Setup nutzen, um das Plugin zu installieren. Füge die Capgo Skills mit dem folgenden Befehl deinem KI-Tool hinzu:

Terminalfenster
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Nutze dann diesen Prompt:

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

Wenn du ein manuelles Setup bevorzugst, installiere das Plugin mit den folgenden Befehlen und befolge die plattformspezifischen Anweisungen unten:

Terminalfenster
npm install @capgo/capacitor-contacts
npx cap sync
import { CapacitorContacts } from '@capgo/capacitor-contacts';

Zugriff anfordern und Kontakte dann mit einer sinnvollen Seitengröße laden, anstatt das gesamte Adressbuch auf einmal abzurufen.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.requestPermissions();
const { contacts } = await CapacitorContacts.getContacts({ limit: 50, offset: 0 });
// Increase offset by limit for the next page instead of loading the full address book.
  • Begründung: Erkläre vor dem Dialog, warum der Kontaktzugriff nötig ist.
  • Paginierung: Vermeide es, ganze Adressbücher auf einmal zu laden.
  • Writes: Das Erstellen von Kontakten erfordert Schreibberechtigung.

Zähle die Gesamtzahl der Kontakte auf dem Gerät.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.countContacts();
console.log(result);

Erstelle einen neuen Kontakt programmatisch.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createContact({ contact: {} });
console.log(result);

Erstelle eine neue Kontaktgruppe.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createGroup({ group: { name: 'example' } });
console.log(result);

Lösche einen Kontakt per ID.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteContactById({ id: 'id-123' });

Lösche eine Gruppe per ID.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteGroupById({ id: 'id-123' });

Zeige einen Kontakt im nativen Kontakt-Viewer an.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.displayContactById({ id: 'id-123' });

Zeigt die native UI zum Erstellen von Kontakten an.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.displayCreateContact();
console.log(result);

Zeigt die native UI zum Aktualisieren eines bestimmten Kontakts an.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.displayUpdateContactById({ id: 'id-123' });

Ruft alle auf dem Gerät verfügbaren Accounts ab.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getAccounts();
console.log(result);

Ruft einen bestimmten Kontakt anhand der ID ab.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getContactById({ id: 'id-123' });
// The result holds sensitive values: use it without logging it.

Ruft alle Kontakte vom Gerät ab.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getContacts();
// The result holds sensitive values: use it without logging it.

Ruft eine bestimmte Gruppe anhand der ID ab.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getGroupById({ id: 'id-123' });
console.log(result);

Ruft alle Kontaktgruppen ab.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.getGroups();
console.log(result);

Prüfen, ob Kontakte auf dem Gerät verfügbar sind.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.isAvailable();
console.log(result);

Prüfen, ob das Plugin auf der aktuellen Plattform unterstützt wird.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.isSupported();
console.log(result);

Die Kontakteinstellungen des Geräts öffnen.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.openSettings();

Einen einzelnen Kontakt über den nativen Kontaktauswahl-Dialog auswählen.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.pickContact();
// The result holds sensitive values: use it without logging it.

Wähle einen oder mehrere Kontakte mit dem nativen Kontakt-Auswahl-Dialog aus.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.pickContacts();
// The result holds sensitive values: use it without logging it.

Bestehenden Kontakt anhand der ID aktualisieren.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.updateContactById({
id: 'id-123',
contact: {},
});

Prüfe den aktuellen Berechtigungsstatus für Kontakte.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.checkPermissions();
console.log(result);

Berechtigungen für den Zugriff auf Kontakte anfordern.

import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.requestPermissions();
console.log(result);

Ergebnis des Zählens von Kontakten.

export interface CountContactsResult {
/**
* Total number of contacts.
*
* @since 1.0.0
*/
count: number;
}

Optionen zum Erstellen eines Kontakts.

export interface CreateContactOptions {
/**
* Contact information to create. The 'id' field will be generated automatically.
*
* @since 1.0.0
*/
contact: Omit<Contact, 'id'>;
}

Ergebnis des Erstellens eines Kontakts.

export interface CreateContactResult {
/**
* The ID of the newly created contact.
*
* @since 1.0.0
*/
id: string;
}

Optionen zum Erstellen einer Gruppe.

export interface CreateGroupOptions {
/**
* Group information to create. The 'id' field will be generated automatically.
*
* @since 1.0.0
*/
group: Omit<Group, 'id'>;
}

Ergebnis der Gruppenerstellung.

export interface CreateGroupResult {
/**
* The ID of the newly created group.
*
* @since 1.0.0
*/
id: string;
}

Optionen zum Löschen eines Kontakts per ID.

export interface DeleteContactByIdOptions {
/**
* The ID of the contact to delete.
*
* @since 1.0.0
*/
id: string;
}

Optionen zum Löschen einer Gruppe per ID.

export interface DeleteGroupByIdOptions {
/**
* The ID of the group to delete.
*
* @since 1.0.0
*/
id: string;
}

Optionen zum Anzeigen eines Kontakts anhand der ID.

export interface DisplayContactByIdOptions {
/**
* The ID of the contact to display.
*
* @since 1.0.0
*/
id: string;
}

Optionen zum Anzeigen der nativen UI zum Erstellen eines Kontakts.

export interface DisplayCreateContactOptions {
/**
* Optional pre-filled contact information for the create UI.
*
* @since 1.0.0
*/
contact?: Omit<Contact, 'id'>;
}

Ergebnis der Anzeige der nativen UI zum Erstellen eines Kontakts.

export interface DisplayCreateContactResult {
/**
* The ID of the created contact, if one was created. Undefined if the user cancelled.
*
* @since 1.0.0
*/
id?: string;
}

Optionen zum Anzeigen der nativen UI zum Aktualisieren eines Kontakts.

export interface DisplayUpdateContactByIdOptions {
/**
* The ID of the contact to update.
*
* @since 1.0.0
*/
id: string;
}

Ergebnis beim Abrufen von Konten.

export interface GetAccountsResult {
/**
* List of accounts available on the device.
*
* @since 1.0.0
*/
accounts: Account[];
}

Diese Seite wird aus dem Plugin generiert src/definitions.ts. Führe den Sync erneut aus, wenn sich das öffentliche API upstream ändert.

Wenn du es nutzt Erste Schritte um Dashboard- und API-Operationen zu planen, verbinde es mit Nutzung von @capgo/capacitor-contacts für die native Funktion bei der Nutzung von @capgo/capacitor-contacts, API Übersicht für Details zur Implementierung im API Overview, Einführung für die Implementierungsdetails in der Einleitung, API Schlüssel für das Implementierungsdetail in API Keys und Geräte für das Implementierungsdetail in Devices.