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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-contacts-permissions

v1.1.0

Published

Check user contacts permissions in React Native

Downloads

18

Readme

☝🏼 React Native Permissions

npm version npm Platform - Android and iOS MIT styled with prettier

Request user permissions on iOS and Android.

⚠️  Branch WIP 2.0.0 : Go to pull request #291 for feedbacks.

Support

| version | react-native version | | ------- | -------------------- | | 2.0.0+ | 0.56.0+ | | 1.1.1 | 0.40.0 - 0.52.2 |

Setup

$ npm install --save react-native-permissions
# --- or ---
$ yarn add react-native-permissions

iOS specific

To allow installation of the needed permission handlers for your project (and only them), react-native-permissions uses CocoaPods. Update the following line with your path to node_modules/ and add it to your podfile:

target 'YourAwesomeProject' do

  # …

  pod 'RNPermissions', :path => '../node_modules/react-native-permissions', :subspecs => [
    'Core',
    ## Uncomment needed permissions
    # 'BluetoothPeripheral',
    # 'Calendars',
    # 'Camera',
    # 'Contacts',
    # 'FaceID',
    # 'LocationAlways',
    # 'LocationWhenInUse',
    # 'MediaLibrary',
    # 'Microphone',
    # 'Motion',
    # 'Notifications',
    # 'PhotoLibrary',
    # 'Reminders',
    # 'Siri',
    # 'SpeechRecognition',
    # 'StoreKit',
  ]

end

Android specific

  1. Add the following lines to android/settings.gradle:
include ':react-native-permissions'
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
  1. Add the compile line to the dependencies in android/app/build.gradle:
dependencies {
  // ...
  implementation project(':react-native-permissions')
}
  1. Add the import and link the package in MainApplication.java:
import com.yonahforst.rnpermissions.RNPermissionsPackage; // <-- Add the import

public class MainApplication extends Application implements ReactApplication {

  // …

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      // …
      new RNPermissionsPackage() // <-- Add it to the packages list
    );
  }

  // …
}

📌 Don't forget to add permissions to AndroidManifest.xml for android and Info.plist for iOS (Xcode >= 8).

API (subject to changes)

Permissions statuses

Promises resolve into one of these statuses:

| Return value | Notes | | ------------------------- | ------------------------------------------------------------------ | | RESULTS.UNAVAILABLE | This feature is not available on this device. | | RESULTS.GRANTED | The permission is granted. | | RESULTS.DENIED | The permission has not been requested / is denied but requestable. | | RESULTS.NEVER_ASK_AGAIN | The permission is not requestable anymore. |

Supported permissions

import { ANDROID_PERMISSIONS, IOS_PERMISSIONS } from "react-native-permissions";

// For Android

// same as PermissionsAndroid
ANDROID_PERMISSIONS.READ_CALENDAR;
ANDROID_PERMISSIONS.WRITE_CALENDAR;
ANDROID_PERMISSIONS.CAMERA;
ANDROID_PERMISSIONS.READ_CONTACTS;
ANDROID_PERMISSIONS.WRITE_CONTACTS;
ANDROID_PERMISSIONS.GET_ACCOUNTS;
ANDROID_PERMISSIONS.ACCESS_FINE_LOCATION;
ANDROID_PERMISSIONS.ACCESS_COARSE_LOCATION;
ANDROID_PERMISSIONS.RECORD_AUDIO;
ANDROID_PERMISSIONS.READ_PHONE_STATE;
ANDROID_PERMISSIONS.CALL_PHONE;
ANDROID_PERMISSIONS.READ_CALL_LOG;
ANDROID_PERMISSIONS.WRITE_CALL_LOG;
ANDROID_PERMISSIONS.ADD_VOICEMAIL;
ANDROID_PERMISSIONS.USE_SIP;
ANDROID_PERMISSIONS.PROCESS_OUTGOING_CALLS;
ANDROID_PERMISSIONS.BODY_SENSORS;
ANDROID_PERMISSIONS.SEND_SMS;
ANDROID_PERMISSIONS.RECEIVE_SMS;
ANDROID_PERMISSIONS.READ_SMS;
ANDROID_PERMISSIONS.RECEIVE_WAP_PUSH;
ANDROID_PERMISSIONS.RECEIVE_MMS;
ANDROID_PERMISSIONS.READ_EXTERNAL_STORAGE;
ANDROID_PERMISSIONS.WRITE_EXTERNAL_STORAGE;

// new ones
ANDROID_PERMISSIONS.ANSWER_PHONE_CALLS;
ANDROID_PERMISSIONS.ACCEPT_HANDOVER;
ANDROID_PERMISSIONS.READ_PHONE_NUMBERS;

// For iOS

IOS_PERMISSIONS.BLUETOOTH_PERIPHERAL;
IOS_PERMISSIONS.CALENDARS;
IOS_PERMISSIONS.CAMERA;
IOS_PERMISSIONS.CONTACTS;
IOS_PERMISSIONS.FACE_ID;
IOS_PERMISSIONS.LOCATION_ALWAYS;
IOS_PERMISSIONS.LOCATION_WHEN_IN_USE;
IOS_PERMISSIONS.MEDIA_LIBRARY;
IOS_PERMISSIONS.MICROPHONE;
IOS_PERMISSIONS.MOTION;
IOS_PERMISSIONS.NOTIFICATIONS;
IOS_PERMISSIONS.PHOTO_LIBRARY;
IOS_PERMISSIONS.REMINDERS;
IOS_PERMISSIONS.SIRI;
IOS_PERMISSIONS.SPEECH_RECOGNITION;
IOS_PERMISSIONS.STOREKIT;

Methods

types used in usage examples

type Permission = keyof ANDROID_PERMISSIONS | keyof IOS_PERMISSIONS;

type PermissionStatus =
  | "granted"
  | "denied"
  | "never_ask_again"
  | "unavailable";

check()

Check one permission status.

Method type

function check(permission: Permission): Promise<PermissionStatus>;

Usage example

import { check, IOS_PERMISSIONS, RESULTS } from "react-native-permissions";

check(RNPermissions.IOS_PERMISSIONS.LOCATION_ALWAYS).then(result => {
  switch (result) {
    case RESULTS.UNAVAILABLE:
      console.log("the feature is not available on this device");
      break;
    case RESULTS.GRANTED:
      console.log("permission is granted");
      break;
    case RESULTS.DENIED:
      console.log("permission is denied, but requestable");
      break;
    case RESULTS.NEVER_ASK_AGAIN:
      console.log("permission is denied and not requestable");
      break;
  }
});

checkMultiple()

Check multiples permissions.

Method type

function checkMultiple<P: Permission>(permissions: P[]): Promise<{ [permission: P]: PermissionStatus }>;

Usage example

import { checkMultiple, IOS_PERMISSIONS } from "react-native-permissions";

checkMultiple([
  IOS_PERMISSIONS.LOCATION_ALWAYS,
  IOS_PERMISSIONS.MEDIA_LIBRARY,
]).then(results => {
  // results.LOCATION_ALWAYS
  // results.MEDIA_LIBRARY
});

request()

Request one permission.

Method type

type NotificationOption =
  | "badge"
  | "sound"
  | "alert"
  | "carPlay"
  | "criticalAlert"
  | "provisional";

type Rationale = {
  title: string;
  message: string;
  buttonPositive: string;
  buttonNegative?: string;
  buttonNeutral?: string;
};

function request(
  permission: string,
  config: {
    notificationOptions?: NotificationOption[];
    rationale?: Rationale;
  } = {},
): Promise<PermissionStatus>;

Usage example

import { request, IOS_PERMISSIONS } from "react-native-permissions";

request(IOS_PERMISSIONS.LOCATION_ALWAYS).then(result => {
  // …
});

requestMultiple()

Request multiples permissions.

Method type

function requestMultiple<P: Permission>(permissions: P[]): Promise<{ [permission: P]: PermissionStatus }>;

Usage example

import { requestMultiple, IOS_PERMISSIONS } from "react-native-permissions";

requestMultiple([
  IOS_PERMISSIONS.LOCATION_ALWAYS,
  IOS_PERMISSIONS.MEDIA_LIBRARY,
]).then(results => {
  // results.LOCATION_ALWAYS
  // results.MEDIA_LIBRARY
});

openSettings()

Open application settings.

Method type

function openSettings(): Promise<boolean>;

Usage example

import { openSettings } from "react-native-permissions";

openSettings().catch(() => console.warn("cannot open settings");

🍎  iOS Notes

  • Permission type BLUETOOTH_PERIPHERAL represents the status of the CBPeripheralManager.
  • If notificationOptions config array is omitted on NOTIFICATIONS request, it will request alert, badge and sound.