A React Native module to get contacts.
npm install @s77rt/react-native-contacts
Add android.permission.READ_CONTACTS
to AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
Add NSContactsUsageDescription
to Info.plist
<key>NSContactsUsageDescription</key>
<string>[USAGE_DESCRIPTION]</string>
Request permission
import { request, PERMISSIONS } from "react-native-permissions";
// Android
request(PERMISSIONS.ANDROID.READ_CONTACTS).then((result) => {
/* … */
});
// iOS
request(PERMISSIONS.IOS.CONTACTS).then((result) => {
/* … */
});
Use Contacts
import Contacts from "@s77rt/react-native-contacts";
Contacts.getAll(["firstName", "lastName", "phoneNumbers", "emailAddresses"])
.then((contacts) => {
console.log(contacts);
})
.catch((error) => {
console.error(error);
});
Name | Arguments | Description |
---|---|---|
getAll |
fields: NonEmptyArray<keyof Contact> |
Get all contacts. Returns a Promise<Contact[]> . |