Skip to content

s77rt/react-native-contacts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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[]>.

License

MIT