$ npm install expo-permissions
If you're using Cocoapods, add the dependency to your Podfile:
pod 'EXPermissions'
and run pod install.
Libraries ➜ Add Files to [your project's name]node_modules ➜ expo-permissions and add EXPermissions.xcodeprojlibEXPermissions.a to your project's Build Phases ➜ Link Binary With LibrariesCmd+R).android/settings.gradle:include ':expo-permissions'
project(':expo-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/expo-permissions/android')
and if not already includedinclude ':expo-permissions-interface'
project(':expo-permissions-interface').projectDir = new File(rootProject.projectDir, '../node_modules/expo-permissions-interface/android')
android/app/build.gradle:compile project(':expo-permissions')
and if not already includedcompile project(':expo-permissions-interface')
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.
Returns a Promise that is resolved with the information about the permission, including status, expiration and scope (if it applies to the permission type).
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.
Returns a Promise that is resolved with the information about the permission, including status, expiration and scope (if it applies to the permission type).
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.NOTIFICATIONSThe 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
statusandexpires, but also Boolean values forallowsSound,allowsAlertandallowsBadge.
Note: On iOS, this does not disambiguate
undeterminedfromdeniedand so will only ever returngrantedorundetermined. 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
NOTIFICATIONSshould always be the same as the status forUSER_FACING_NOTIFICATIONS.
Permissions.USER_FACING_NOTIFICATIONSThe 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
statusandexpires, but also Boolean values forallowsSound,allowsAlertandallowsBadge.
Note: Android does not differentiate between permissions for local and remote notifications, so status of permission for
USER_FACING_NOTIFICATIONSshould always be the same as the status forNOTIFICATIONS.
Permissions.LOCATIONThe permission type for location access.
Permissions.CAMERAThe permission type for photo and video taking.
Permissions.AUDIO_RECORDINGThe permission type for audio recording.
Permissions.CONTACTSThe permission type for reading contacts.
Permissions.CAMERA_ROLLThe permission type for reading or writing to the camera roll.
Permissions.CALENDARThe permission type for reading or writing to the calendar.
Permissions.REMINDERSThe permission type for reading or writing reminders (iOS only).
© 2010 - cnpmjs.org x YWFE | Home | YWFE