Skip to main content

@napacitor/contacts

Contacts plugin: read all contacts on the device and open the system contact picker. Wraps the .NET MAUI Contacts API.

Installation​

To use npm:

npm install @napacitor/contacts

To use yarn:

yarn add @napacitor/contacts

Sync native files:

npx nap sync

Usage​

import { Contacts } from '@napacitor/contacts';

// ── Read all contacts ────────────────────────────────────
const contacts = await Contacts.getContacts();
for (const contact of contacts) {
console.log(contact.displayName, contact.phones, contact.emails);
}

// ── System contact picker (returns null on cancel) ────────
const picked = await Contacts.pickContact();
if (picked) {
console.log(picked.id, picked.displayName);
console.log(picked.phones.map((p) => p.phoneNumber));
console.log(picked.emails.map((e) => e.emailAddress));
}

How It Works​

Wraps the .NET MAUI Contacts.Default facade: getContacts() calls GetAllAsync() to read all contacts on the device (its cancellationToken parameter is not supported on Android); pickContact() calls PickContactAsync() on the UI thread to present the system contact dialog (null on cancel). On the C# side, the Contacts type is fully qualified with the Communication alias as required by the official docs (to avoid a namespace conflict on iOS/macOS); the Emails / Phones collections of Contact are mapped one by one into result DTOs.

Permissions​

Android​

Declare the READ_CONTACTS permission in Platforms/Android/AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_CONTACTS" />

Alternatively, declare it in Platforms/Android/MainApplication.cs with the [assembly: UsesPermission(Android.Manifest.Permission.ReadContacts)] assembly attribute.

iOS​

No additional configuration required by the official docs. Note: when calling getContacts() to read the contact store, the system may require the app to declare NSContactsUsageDescription in Info.plist (the reason shown to the user when requesting access), otherwise the call fails.

Windows​

Per the official docs, picking a contact is not supported; pickContact() throws UNSUPPORTED.

API​

getContacts()​

Gets all contacts on the device (throws when permission is denied).

Returns: Promise<ContactInfo[]>

pickContact()​

Opens the system contact picker to select a single contact; returns null when the user cancels (not supported on Windows, throws UNSUPPORTED).

Returns: Promise<ContactInfo | null>

Interfaces​

ContactInfo​

PropTypeDescription
idstringContact ID.
displayNamestringDisplay name (inferred from the name when not set).
namePrefixstringName prefix (e.g. 'Dr.').
givenNamestringGiven name.
middleNamestringMiddle name.
familyNamestringFamily name.
nameSuffixstringName suffix (e.g. 'Jr.').
emailsContactEmail[]List of email addresses.
phonesContactPhone[]List of phone numbers.

ContactEmail​

PropTypeDescription
emailAddressstringEmail address.

ContactPhone​

PropTypeDescription
phoneNumberstringPhone number.