
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
expo-permissions
Advanced tools
An Expo universal module to prompt for permission to access device sensors and personal data
expo-permissions
lets you prompt for various permissions to access device sensors, personal data, etc.
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.
If your app is running in Expo then everything is already set up for you, just import { Permissions } from 'expo';
Otherwise, you need to install the package from npm
registry.
yarn add expo-permissions
or npm install expo-permissions
Also, make sure that you have expo-core installed, as it is required by expo-permissions
to work properly.
Add these dependencies to your Podfile
:
pod 'EXPermissions', path: '../node_modules/expo-permissions/ios'
pod 'EXPermissionsInterface', path: '../node_modules/expo-permissions-interface/ios'
and run pod install
under the parent directory of your Podfile
.
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')
android/app/build.gradle
:
compile project(':expo-permissions')
and if not already included
compile project(':expo-permissions-interface')
new PermissionsPackage()
to your module registry provider in MainApplication.java
. If consuming the Flutter plugin for this module, this is already done for you.Expo.Permissions.getAsync(...permissionTypes)
Determines whether your app has already been granted access to the provided permissions types.
Returns a Promise
that is resolved with the information about the permissions, including status, expiration and scope (if it applies to the permission type).
Top-level status
and exprires
keys stores combined info of each component permission that is asked for.
If any permission resulted in negative result than that negative result is propagated here, that means top-level values are positive only if all component values are positive.
Examples [...componentsValues] => topLevelStatus
:
[granted, denied, granted] => denied
[granted, granted, granted] => granted
{
status, // combined status of all component permissions being asked for, if any of has status !== 'granted' then that status is propagated here
expires, // combined expires of all permissions being asked for, same as status
permissions: { // an object with an entry for each permission requested
[Permissions.TYPE]: {
status,
expires,
... // any additional permission-specific fields
},
...
},
}
async function alertIfRemoteNotificationsDisabledAsync() {
const { Permissions } = Expo;
const { status } = await Permissions.getAsync(Permissions.NOTIFICATIONS);
if (status !== 'granted') {
alert('Hey! You might want to enable notifications for my app, they are good.');
}
}
async function checkMultiPermissions() {
const { Permissions } = Expo;
const { status, expires, permissions } = await Permissions.getAsync(Permissions.CALENDAR, Permissions.CONTACTS)
if (status !== 'granted') {
alert('Hey! You heve not enabled selected permissions');
}
}
Expo.Permissions.askAsync(...types)
Prompt the user for types of permissions. If they have already granted access, response will be success.
Same as for Permissions.getAsync
async function getLocationAsync() {
const { Location, Permissions } = Expo;
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
andexpires
, but also Boolean values forallowsSound
,allowsAlert
andallowsBadge
.
Note: On iOS, this does not disambiguate
undetermined
fromdenied
and so will only ever returngranted
orundetermined
. 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 forUSER_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
andexpires
, but also Boolean values forallowsSound
,allowsAlert
andallowsBadge
.
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 forNOTIFICATIONS
.
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).
Expo.Permissions.SYSTEM_BRIGHTNESS
The permissions type for changing brighness of the screen
app.json
If you specified android.permissions
inside your app.json
(read more about configuration) you have to use values corresponding to their Expo.Permissions
equivalents.
Expo | Android |
---|---|
LOCATION | ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION |
CAMERA | CAMERA |
AUDIO_RECORDING | RECORD_AUDIO |
CONTACTS | READ_CONTACTS |
CAMERA_ROLL | READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE |
CALENDAR | READ_CALENDAR, WRITE_CALENDAR |
FAQs
Allows you prompt for various permissions to access device sensors, personal data, etc.
We found that expo-permissions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 30 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.