@s77rt/react-native-contacts
v0.1.1
Published
A React Native module to get contacts.
Downloads
9
Readme
@s77rt/react-native-contacts
A React Native module to get contacts.
Installation
npm install @s77rt/react-native-contacts
Android
Add android.permission.READ_CONTACTS
to AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" />
iOS
Add NSContactsUsageDescription
to Info.plist
<key>NSContactsUsageDescription</key>
<string>[USAGE_DESCRIPTION]</string>
Usage
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);
});
Methods
| Name | Arguments | Description |
| :------: | :------------------------------------: | :-----------------------------------------------: |
| getAll
| fields: NonEmptyArray<keyof Contact>
| Get all contacts. Returns a Promise<Contact[]>
. |