14.4.0 • Published 8 months ago

expo-permissions v14.4.0

Weekly downloads
158,004
License
MIT
Repository
github
Last release
8 months ago

expo-permissions

Installation

iOS (Cocoapods)

If you're using Cocoapods, add the dependency to your Podfile:

pod 'EXPermissions'

and run pod install.

iOS (no Cocoapods)

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesexpo-permissions and add EXPermissions.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libEXPermissions.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R).

Android

  1. Append the following lines to android/settings.gradle:
    include ':expo-permissions'
    project(':expo-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/expo-permissions/android')
    and if not already included
    include ':expo-permissions-interface'
    project(':expo-permissions-interface').projectDir = new File(rootProject.projectDir, '../node_modules/expo-permissions-interface/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    compile project(':expo-permissions')
    and if not already included
    compile project(':expo-permissions-interface')

Introduction

When it comes to adding functionality that can access potentially sensitive information on a user's device, such as their location, or possibly send them possibly unwanted push notifications, you will need to ask the user for their permission first. Unless you've already asked their permission, then no need. And so we have the Permissions module.

If you are deploying your app to the Apple iTunes Store, you should consider adding additional metadata to your app in order to customize the system permissions dialog and explain why your app requires permissions. See more info in the App Store Deployment Guide.

Permissions.getAsync(type)

Determines whether your app has already been granted access to the provided permission type.

Arguments

  • type (string) -- The name of the permission.

Returns

Returns a Promise that is resolved with the information about the permission, including status, expiration and scope (if it applies to the permission type).

Example

import { Permissions } from 'expo-permissions';

async function alertIfRemoteNotificationsDisabledAsync() {
  const { status } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
  if (status !== 'granted') {
    alert('Hey! You might want to enable notifications for my app, they are good.');
  }
}

Permissions.askAsync(type)

Prompt the user for a permission. If they have already granted access, response will be success.

Arguments

  • type (string) -- The name of the permission.

Returns

Returns a Promise that is resolved with the information about the permission, including status, expiration and scope (if it applies to the permission type).

Example

import { Location } from 'expo';
import { Permissions } from 'expo-permissions';

async function getLocationAsync() {
  const { status } = await Permissions.askAsync(Permissions.LOCATION);
  if (status === 'granted') {
    return Location.getCurrentPositionAsync({enableHighAccuracy: true});
  } else {
    throw new Error('Location permission not granted');
  }
}

Permissions.NOTIFICATIONS

The permission type for user-facing notifications and remote push notifications.

Note: On iOS, asking for this permission asks the user not only for permission to register for push/remote notifications, but also for showing notifications as such. At the moment remote notifications will only be received when notifications are permitted to play a sound, change the app badge or be displayed as an alert. As iOS is more detailed when it comes to notifications permissions, this permission status will contain not only status and expires, but also Boolean values for allowsSound, allowsAlert and allowsBadge.

Note: On iOS, this does not disambiguate undetermined from denied and so will only ever return granted or undetermined. This is due to the way the underlying native API is implemented.

Note: Android does not differentiate between permissions for local and remote notifications, so status of permission for NOTIFICATIONS should always be the same as the status for USER_FACING_NOTIFICATIONS.

Permissions.USER_FACING_NOTIFICATIONS

The permission type for user-facing notifications. This does not register your app to receive remote push notifications; see the NOTIFICATIONS permission.

Note: iOS provides more detailed permissions, so the permission status will contain not only status and expires, but also Boolean values for allowsSound, allowsAlert and allowsBadge.

Note: Android does not differentiate between permissions for local and remote notifications, so status of permission for USER_FACING_NOTIFICATIONS should always be the same as the status for NOTIFICATIONS.

Permissions.LOCATION

The permission type for location access.

Permissions.CAMERA

The permission type for photo and video taking.

Permissions.AUDIO_RECORDING

The permission type for audio recording.

Permissions.CONTACTS

The permission type for reading contacts.

Permissions.CAMERA_ROLL

The permission type for reading or writing to the camera roll.

Permissions.CALENDAR

The permission type for reading or writing to the calendar.

Permissions.REMINDERS

The permission type for reading or writing reminders (iOS only).

consultadigitaltenor-gif-boothindkoebslistenatysoz-testblindajereact-native-holper-storybookloyalty-core-componentsrn-pdf-reader-offlinereact-native-slider-kf@expocraft/core@everything-registry/sub-chunk-1630temp-csv-expotrv-expounitx-uiuniversal-modules-core@hammadj/react-native-gifted-chat@infinitebrahmanuniverse/nolb-exposwapnilwable2510elibraryswapnilwable2510willyappzippi-market-core@harrysong/taro-rnob-react-native-web-ui-componentspuzzl-w2-onboardingdeployfrontendridecabridersales-sync-mobilern-image-picker-the-ultimate-release-by-eliasrnshellsharedtextsouge-shop-packagespfystickersmash@onytgvx/multiple-image-selector@kfox/expo@mifind/taro-rn@onytgvx/expo-image-picker-multiplezeninvest@fmichenaud/expo-multiple-image-picker@kafudev/react-native-core@kafudev/react-native-shell@socian/smart-assistantpcmli.umbrella.react-nativecode7-boteria-mobile-rnpolseposetrackerreact-native-app-helpersreact-native-json-formsreact-native-modular-bootstrapperreact-native-fusionchartreact-native-chatwhatreact-native-code7-boteriareact-native-extended-gifted-chatreact-native-extlibreact-native-expo-image-cropperreact-native-template-gaussreact-native-template-gaussfleettemplatereact-native-universal-modulesreact-native-universal-modules-corereact-native-web-appreact-native-web-permissionsreact-native-web-ui-componentsconsulta-digital@puzzlpayroll/employee-onboardingexpo-torqexpo-multiple-images-pickerexpo-permissions-hooksexpo-can-cropperexpo-filedownloadexpo-appexpo-inputsexpo-image-picker-multipleenntte_app_almacen_arestantenntte_app_almacen_auxilabenntte_app_almacen_cataenntte_app_almacen_ederlantafallaenntte_app_almacen_garnicaenntte_app_almacen_hergom_sdkenntte_app_almacen_sabaterenntte_app_almacen_symagaenntte_app_almacen_aratubo@riversilica_narendra/expo-permissions-12.1.1@riversilica_narendra/ios@riversilica_narendra/android@unimodules/react-native-platform@universal-modules/react-native-platformjoseph-onboarding@virtuelabs-io/rapido-modules@ronas-it/react-native-starterformiusfoozard-mobile-components@agreejs/taro-rnmairiesimplonganeyipmg-app-col-library@colorfulwindmill/five-films-service@cognativ/permissionsiat-app-alpha@cuongweallnet/rn-gifted-chatncmb-expo-pushmoor-react-native-components
14.4.0

8 months ago

14.3.0

9 months ago

14.2.0

10 months ago

14.2.1

10 months ago

14.1.2

12 months ago

14.1.0

1 year ago

14.1.1

1 year ago

14.0.0

2 years ago

13.2.0

2 years ago

13.1.1

2 years ago

13.1.0

2 years ago

13.0.2

3 years ago

13.0.3

3 years ago

13.0.1

3 years ago

13.0.0

3 years ago

12.1.1

3 years ago

12.1.0

3 years ago

12.0.1

3 years ago

12.0.0

3 years ago

11.0.0

3 years ago

10.0.0

3 years ago

9.3.0

4 years ago

9.2.0

4 years ago

9.1.0

4 years ago

9.0.1

4 years ago

9.0.0

4 years ago

8.2.0

4 years ago

8.1.0

4 years ago

8.0.0

4 years ago

8.0.0-rc.0

5 years ago

7.0.0

5 years ago

7.0.0-rc.0

5 years ago

6.0.0

5 years ago

6.0.0-rc.0

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

5.0.0-rc.0

5 years ago

4.0.1-beta.0

5 years ago

4.0.0

5 years ago

3.0.0

5 years ago

2.1.0-alpha.0

5 years ago

2.0.0

5 years ago

2.0.0-rc.2

5 years ago

2.0.0-rc.1

5 years ago

2.0.0-rc.0

5 years ago

1.0.2

5 years ago

1.2.0

5 years ago

1.2.0-rc.1

5 years ago

1.2.0-rc.0

6 years ago

1.1.0

6 years ago

1.1.0-rc.1

6 years ago

1.1.0-rc.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-rc.2

6 years ago

1.0.0-rc.1

6 years ago

1.0.0-rc.0

6 years ago

0.0.1

6 years ago