Skip to content
  • Android
  • iOS
  • Web

Contacts

Search and manage device contacts on Android and iOS, or an app-owned address book on the web.

API notes

  • Call getPermissions() to check access or requestPermissions({ write: true }) from a user action before editing device contacts. iOS can grant limited access to selected contacts.
  • Search by name, company, job title, phone or email. Pass offset and limit to list() and use hasNextPage to fetch more results.
  • Manage a contact by its opaque ID with get(), update() and remove(). Android linked or read-only contacts can be managed in the system Contacts app.

Examples

Quick start

For Expo, set contactsPermission on the nayan-ui plugin and rebuild. Browsers persist their app-owned contacts in IndexedDB.

nayan-ui/contacts
import { contacts } from 'nayan-ui/contacts';

export async function searchContacts(search: string, offset = 0) {
  const { read } = await contacts.requestPermissions();
  if (read.status !== 'granted' && read.status !== 'limited') return null;
  return contacts.list({ search, offset, limit: 25 });
}

Create a contact

Call from a user action. On native, edits are scoped to the contacts and permissions the OS grants.

nayan-ui/contacts
import { contacts } from 'nayan-ui/contacts';

export async function addAda() {
  const { read, write } = await contacts.requestPermissions({ write: true });
  if ([read, write].some(({ status }) => status !== 'granted' && status !== 'limited')) return null;
  return contacts.create({ givenName: 'Ada', familyName: 'Lovelace' });
}

Edit and remove contacts by ID

Omitted fields are preserved. Use null to clear a text field or an empty array to clear phones or emails. remove() returns false when the contact is missing.

nayan-ui/contacts
import { contacts } from 'nayan-ui/contacts';

export async function clearWorkDetails(id: string) {
  const { write } = await contacts.getPermissions();
  if (write.status !== 'granted' && write.status !== 'limited') return null;
  return contacts.update(id, { company: null, jobTitle: null, emails: [] });
}

export async function deleteContact(id: string) {
  const { write } = await contacts.getPermissions();
  if (write.status !== 'granted' && write.status !== 'limited') return false;
  return contacts.remove(id);
}

Tags