expo-contacts
Version: 55.0.6
Provides access to the phone’s system contacts. Read, create, update, and delete contacts.
Installation
npx expo install expo-contacts
Usage
import * as Contacts from 'expo-contacts';
// Request permissions
const { status } = await Contacts.requestPermissionsAsync();
if (status === 'granted') {
// Get contacts
const { data } = await Contacts.getContactsAsync({
fields: [Contacts.Fields.PhoneNumbers],
});
if (data.length > 0) {
console.log('First contact:', data[0]);
}
}
API Reference
Methods
requestPermissionsAsync()
() => Promise<PermissionResponse>
Requests contacts permissions
getContactsAsync(contactQuery)
(contactQuery?: ContactQuery) => Promise<ContactResponse>
Fetches contactsconst { data, hasNextPage, hasPreviousPage } = await Contacts.getContactsAsync({
pageSize: 20,
fields: [Contacts.Fields.Name, Contacts.Fields.PhoneNumbers],
});
getContactByIdAsync(id, fields)
(id: string, fields?: Field[]) => Promise<Contact | undefined>
Gets contact by ID
addContactAsync(contact, containerId)
(contact: Contact, containerId?: string) => Promise<string>
Adds new contactconst id = await Contacts.addContactAsync({
[Contacts.Fields.FirstName]: 'John',
[Contacts.Fields.LastName]: 'Doe',
[Contacts.Fields.PhoneNumbers]: [{
number: '555-1234',
label: 'mobile',
}],
});
updateContactAsync(contact)
(contact: Contact) => Promise<string>
Updates existing contact
removeContactAsync(contactId)
(contactId: string) => Promise<void>
Removes contact
| Platform | Supported |
|---|
| iOS | ✅ |
| Android | ✅ |
| Web | ❌ |
Permissions
iOS: Add to app.json:
{
"plugins": [
[
"expo-contacts",
{
"contactsPermission": "Allow app to access your contacts."
}
]
]
}
Resources