npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-native-phonebook

v1.0.2

Published

React Native library to launch phonebook/contacts app and return selected contact details

Readme

React Native Phonebook

A React Native library that allows you to launch the native phonebook/contacts app and retrieve selected contact details.

Features

  • 📱 Launch native contacts app on iOS and Android
  • 🔐 Handle contacts permissions automatically
  • 📞 Retrieve comprehensive contact information (name, phone numbers, emails, addresses, etc.)
  • 🎯 Support for both Promise and Callback patterns
  • 📦 TypeScript support with full type definitions
  • 🔧 Easy to integrate and use

Installation

npm install react-native-phonebook
# or
yarn add react-native-phonebook

iOS Setup

  1. Install pods:
cd ios && pod install
  1. Add the following to your ios/YourApp/Info.plist:
<key>NSContactsUsageDescription</key>
<string>This app needs access to contacts to let you select contacts.</string>

Android Setup

  1. Add the following to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_CONTACTS" />
  1. The library will automatically register the native module.

Usage

Basic Usage

import Phonebook from 'react-native-phonebook';

// Using Promise
const selectContact = async () => {
  try {
    const result = await Phonebook.openPhonebook({
      title: 'Select a Contact',
      message: 'Choose a contact to import',
      allowMultipleSelection: false,
    });

    if (result.success && result.contacts) {
      console.log('Selected contact:', result.contacts[0]);
    } else {
      console.log('No contact selected or error:', result.error);
    }
  } catch (error) {
    console.error('Error opening phonebook:', error);
  }
};

// Using Callback
const selectContactWithCallback = () => {
  Phonebook.openPhonebookWithCallback(
    (result) => {
      if (result.success && result.contacts) {
        console.log('Selected contact:', result.contacts[0]);
      } else {
        console.log('No contact selected or error:', result.error);
      }
    },
    {
      title: 'Select a Contact',
      message: 'Choose a contact to import',
      allowMultipleSelection: false,
    }
  );
};

Permission Handling

import Phonebook from 'react-native-phonebook';

// Check if permission is granted
const checkPermission = async () => {
  const hasPermission = await Phonebook.hasContactsPermission();
  console.log('Has permission:', hasPermission);
};

// Request permission
const requestPermission = async () => {
  const granted = await Phonebook.requestContactsPermission();
  if (granted) {
    console.log('Permission granted');
  } else {
    console.log('Permission denied');
  }
};

// Check if phonebook is available
const checkAvailability = async () => {
  const isAvailable = await Phonebook.isPhonebookAvailable();
  console.log('Phonebook available:', isAvailable);
};

API Reference

Methods

openPhonebook(options?: PhonebookOptions): Promise<PhonebookResult>

Opens the native phonebook/contacts app and returns a Promise with the selected contact(s).

Parameters:

  • options (optional): Configuration options for the phonebook picker

Returns: Promise that resolves with a PhonebookResult object

openPhonebookWithCallback(callback: PhonebookCallback, options?: PhonebookOptions): void

Opens the native phonebook/contacts app with a callback function.

Parameters:

  • callback: Function to call when contact selection is complete
  • options (optional): Configuration options for the phonebook picker

isPhonebookAvailable(): Promise<boolean>

Checks if the phonebook/contacts app is available on the device.

Returns: Promise that resolves to true if available, false otherwise

requestContactsPermission(): Promise<boolean>

Requests permission to access contacts.

Returns: Promise that resolves to true if permission granted, false otherwise

hasContactsPermission(): Promise<boolean>

Checks if the app has permission to access contacts.

Returns: Promise that resolves to true if permission granted, false otherwise

Types

PhonebookOptions

interface PhonebookOptions {
  title?: string;                    // Title for the contact picker
  message?: string;                  // Message for the contact picker
  allowMultipleSelection?: boolean;  // Allow selecting multiple contacts
}

PhonebookResult

interface PhonebookResult {
  success: boolean;        // Whether the operation was successful
  contacts?: Contact[];    // Array of selected contacts (if any)
  error?: string;          // Error message (if any)
}

Contact

interface Contact {
  id: string;                    // Unique contact identifier
  name: string;                  // Full name
  firstName?: string;            // First name
  lastName?: string;             // Last name
  phoneNumbers: PhoneNumber[];   // Array of phone numbers
  emails: Email[];              // Array of email addresses
  organization?: string;         // Organization name
  jobTitle?: string;            // Job title
  addresses: Address[];         // Array of addresses
  birthday?: string;            // Birthday (YYYY-MM-DD format)
  note?: string;                // Contact note
}

PhoneNumber

interface PhoneNumber {
  label: string;    // Phone number label (e.g., "Mobile", "Home", "Work")
  number: string;   // Phone number
}

Email

interface Email {
  label: string;    // Email label (e.g., "Home", "Work")
  email: string;    // Email address
}

Address

interface Address {
  label: string;        // Address label (e.g., "Home", "Work")
  street?: string;      // Street address
  city?: string;        // City
  state?: string;       // State/Province
  postalCode?: string;  // Postal/ZIP code
  country?: string;     // Country
}

Example

Check out the example/ directory for a complete working example.

To run the example:

cd example
npm install
# For iOS
cd ios && pod install && cd ..
npm run ios
# For Android
npm run android

Platform Differences

iOS

  • Uses CNContactPickerViewController from the ContactsUI framework
  • Automatically handles permission requests
  • Supports all contact fields including addresses, birthdays, and notes

Android

  • Uses the native Android contact picker (Intent.ACTION_PICK)
  • Requires READ_CONTACTS permission
  • Retrieves comprehensive contact information including phone numbers, emails, and addresses

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Troubleshooting

Common Issues

  1. Permission denied on Android: Make sure you've added the READ_CONTACTS permission to your AndroidManifest.xml

  2. Permission denied on iOS: Make sure you've added the NSContactsUsageDescription key to your Info.plist

  3. Module not found: Make sure you've run pod install for iOS and rebuilt your app

  4. No contacts returned: Check if the user has granted contacts permission and if there are contacts in the device

Getting Help

If you encounter any issues or have questions, please:

  1. Check the Issues page
  2. Create a new issue with detailed information about your problem
  3. Include your React Native version, platform, and error messages

Changelog

1.0.0

  • Initial release
  • Support for iOS and Android
  • Promise and callback patterns
  • Full TypeScript support
  • Comprehensive contact information retrieval