Guide
How to use Contacts in Capacitor
Using @capgo/capacitor-contacts
Capacitor Contacts Plugin interface for managing device contacts.
Install
bun add @capgo/capacitor-contacts
bunx cap sync
bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.
Import
import { CapacitorContacts } from '@capgo/capacitor-contacts';
API at a glance
| Method | Description |
|---|---|
countContacts |
Count the total number of contacts on the device. |
createContact |
Create a new contact programmatically. |
createGroup |
Create a new contact group. |
deleteContactById |
Delete a contact by ID. |
deleteGroupById |
Delete a group by ID. |
displayContactById |
Display a contact using the native contact viewer. |
displayCreateContact |
Display the native create contact UI. |
displayUpdateContactById |
Display the native update contact UI for a specific contact. |
getAccounts |
Get all accounts available on the device. |
getContactById |
Get a specific contact by ID. |
getContacts |
Get all contacts from the device. |
getGroupById |
Get a specific group by ID. |
getGroups |
Get all contact groups. |
isAvailable |
Check if contacts are available on the device. |
isSupported |
Check if the plugin is supported on the current platform. |
openSettings |
Open the device's contacts settings. |
pickContact |
Pick a single contact using the native contact picker. |
pickContacts |
Pick one or more contacts using the native contact picker. |
updateContactById |
Update an existing contact by ID. |
checkPermissions |
Check the current permission status for contacts. |
requestPermissions |
Request permissions to access contacts. |
Examples
countContacts()
Count the total number of contacts on the device.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.countContacts();
console.log(result);
createContact()
Create a new contact programmatically.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createContact({ contact: {} });
console.log(result);
createGroup()
Create a new contact group.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
const result = await CapacitorContacts.createGroup({ group: { name: 'example' } });
console.log(result);
deleteContactById()
Delete a contact by ID.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteContactById({ id: 'id-123' });
deleteGroupById()
Delete a group by ID.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.deleteGroupById({ id: 'id-123' });
displayContactById()
Display a contact using the native contact viewer.
import { CapacitorContacts } from '@capgo/capacitor-contacts';
await CapacitorContacts.displayContactById({ id: 'id-123' });
The table above lists the 21 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.
Full reference
Keep going from Using @capgo/capacitor-contacts
If you are using Using @capgo/capacitor-contacts to plan dashboard and API operations, connect it with @capgo/capacitor-contacts for the implementation detail in @capgo/capacitor-contacts, Getting Started for the implementation detail in Getting Started, API Overview for the implementation detail in API Overview, Introduction for the implementation detail in Introduction, and API Keys for the implementation detail in API Keys.