Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nativescript-community/perms

nativescript-community9.7kApache-2.03.0.4TypeScript support: included

An unified permissions API for NativeScript on iOS and Android.

NativeScript, JavaScript, Android, iOS, Vue

readme

@nativescript-community/perms

Downloads per month NPM Version

An unified permissions API for NativeScript on iOS and Android.


iOS Demo Android Demo

Table of Contents

Installation

Run the following command from the root of your project:

ns plugin add @nativescript-community/perms

API

Permissions statuses

Promises resolve into [status:Status, always:boolean] where status is one of these statuses:

Return value Notes
authorized User has authorized this permission
denied User has denied this permission at least once. On iOS this means that the user will not be prompted again. Android users can be prompted multiple times until they select 'Never ask me again'
limited iOS - this means the permission is granted but with limitations
restricted iOS - this means user is not able to grant this permission, either because it's not supported by the device or because it has been blocked by parental controls. Android - this means that the user has selected 'Never ask me again' while denying permission
undetermined User has not yet been prompted with a permission dialog

Supported permissions types

The current supported permissions are:

| | Type | iOS | Android | | ------------------ | ------------------- | --- | ------- | | Location | location | ✔ | ✔ | | Camera | camera | ✔ | ✔ | | Microphone | microphone | ✔ | ✔ | | Photos | photo | ✔ | ✔ | | Videos | video | ❌ | ✔ (api >= 33) | | Audio | audio | ❌ | ✔ (api >= 33) | | Contacts | contacts | ✔ | ✔ | | Events | event | ✔ | ✔ | | Bluetooth | bluetooth | ✔ | ✔(api >= 31) | | Reminders | reminder | ✔ | ❌ | | Push Notifications | notification | ✔ | ✔ (api >= 33) | | Background Refresh | backgroundRefresh | ✔ | ❌ | | Speech Recognition | speechRecognition | ✔ | ❌ | | Media Library | mediaLibrary | ✔ | ❌ | | Motion Activity | motion | ✔ | ❌ | | Storage | storage | ❌️ | ✔ | | Phone Call | callPhone | ❌️ | ✔ | | Read SMS | readSms | ❌️ | ✔ | | Receive SMS | receiveSms | ❌️ | ✔ | | Media Location | mediaLocation | ❌️ | ✔(api >= 29) | | Bluetooth Scan | bluetoothScan | ❌️ | ✔(api >= 31) | | Bluetooth Connect | bluetoothConnect | ❌️ | ✔(api >= 31) |

Methods

Method Name Arguments Notes
check() type - Returns a promise with the permission status. See iOS Notes for special cases
request() type - Accepts any permission type except backgroundRefresh. If the current status is undetermined, shows the permission dialog and returns a promise with the resulting status. Otherwise, immediately return a promise with the current status. See iOS Notes for special cases
checkMultiple() {[key:string]:Record<string, any>} - Accepts an array of permission types and returns a promise with an object mapping permission types to statuses
getTypes() none - Returns an array of valid permission types
openSettings() none - Switches the user to the settings page of your app
canOpenSettings() none - Returns a boolean indicating if the device supports switching to the settings page

iOS Notes

  • Permission type bluetooth represents the status of the CBPeripheralManager. Don't use this if only need CBCentralManager
  • Permission type location accepts a second parameter for request() and check(); the second parameter is a string, either always or whenInUse (default).
  • Permission type notification accepts a second parameter for request(). The second parameter is an array with the desired alert types. Any combination of alert, badge and sound (default requests all three).
  • iOS 12+: The second parameter also takes this type inside of the array providesAppNotificationSettings.
  • If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project
import { check as checkPermission, request as requestPermission } from '@nativescript-community/perms';

// example
checkPermission('location', { type: 'always' }).then(response => {
  this.setState({ locationPermission: response[0] })
})

requestPermission('location', { type: 'always' }).then(response => {
  this.setState({ locationPermission: response[0] })
})

requestPermission('notification', { type: ['alert', 'badge'] }).then(
  response => {
    this.setState({ notificationPermission: response[0] })
  },
)
  • You cannot request microphone permissions on the simulator.
  • With Xcode 8, you now need to add usage descriptions for each permission you will request. Open Xcode ➜ Info.plist ➜ Add a key (starting with "Privacy - ...") with your kit specific permission.

Example: If you need Contacts permission you have to add the key Privacy - Contacts Usage Description.

3cde3b44-7ffd-11e6-918b-63888e33f983

App Store submission disclaimer

If you need to submit you application to the AppStore, you need to add to your Info.plist all *UsageDescription keys with a string value explaining to the user how the app uses this data. Even if you don't use them.

So before submitting your app to the App Store, make sure that in your Info.plist you have the following keys:

<key>NSBluetoothPeripheralUsageDescription</key>
<string>Some description</string>
<key>NSCalendarsUsageDescription</key>
<string>Some description</string>
<key>NSCameraUsageDescription</key>
<string>Some description</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Some description</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Some description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Some description</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>Some description</string>
<key>NSAppleMusicUsageDescription</key>
<string>Some description</string>
<key>NSMotionUsageDescription</key>
<string>Some description</string>

This is required because during the phase of processing in the App Store submission, the system detects that you app contains code to request the permission X but don't have the UsageDescription key and then it rejects the build.

Please note that it will only be shown to the users the usage descriptions of the permissions you really require in your app.

You can find more information about this issue in #46.

Android Notes

  • check and request also allows you to directly pass android permission(s) as a value or an array. This would allow to request any new permission without a required update of this plugin
  • All required permissions also need to be included in the AndroidManifest.xml file before they can be requested. Otherwise request() will immediately return denied.
  • You can request write access to any of these types by also including the appropriate write permission in the AndroidManifest.xml file. Read more here.

  • Permissions are automatically accepted for targetSdkVersion < 23 but you can still use check() to check if the user has disabled them from Settings.

You might need to elevate the targetSdkVersion version in your build.gradle:

android {
  compileSdkVersion 23 // ← set at least 23
  buildToolsVersion "23.0.1"  // ← set at least 23.0.0

  defaultConfig {
    minSdkVersion 16
    targetSdkVersion 23 // ← set at least 23
    // ...

Troubleshooting

Q: iOS - App crashes as soon as I request permission

A: Starting with Xcode 8, you need to add permission descriptions. See iOS notes for more details. Thanks to @jesperlndk for discovering this.

Q: iOS - App crashes when I change permission from settings

A: This is normal. iOS restarts your app when your privacy settings change. Just google "iOS crash permission change"

Demos and Development

Repo Setup

The repo uses submodules. If you did not clone with --recursive then you need to call

git submodule update --init

The package manager used to install and link dependencies must be pnpm or yarn. npm wont work.

To develop and test: if you use yarn then run yarn if you use pnpm then run pnpm i

Interactive Menu:

To start the interactive menu, run npm start (or yarn start or pnpm start). This will list all of the commonly used scripts.

Build

npm run build.all

WARNING: it seems yarn build.all wont always work (not finding binaries in node_modules/.bin) which is why the doc explicitly uses npm run

Demos

npm run demo.[ng|react|svelte|vue].[ios|android]

npm run demo.svelte.ios # Example

Demo setup is a bit special in the sense that if you want to modify/add demos you dont work directly in demo-[ng|react|svelte|vue] Instead you work in demo-snippets/[ng|react|svelte|vue] You can start from the install.ts of each flavor to see how to register new demos

Contributing

Update repo

You can update the repo files quite easily

First update the submodules

npm run update

Then commit the changes Then update common files

npm run sync

Then you can run yarn|pnpm, commit changed files if any

Update readme

npm run readme

Update doc

npm run doc

Publish

The publishing is completely handled by lerna (you can add -- --bump major to force a major release) Simply run

npm run publish

modifying submodules

The repo uses https:// for submodules which means you won't be able to push directly into the submodules. One easy solution is t modify ~/.gitconfig and add

[url "ssh://git@github.com/"]
    pushInsteadOf = https://github.com/

Questions

If you have any questions/issues/comments please feel free to create an issue or start a conversation in the NativeScript Community Discord.

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

3.0.4 (2025-03-27)

Bug Fixes

  • add missing case statement for limited contact access (53c46e4), closes #33

3.0.3 (2025-01-27)

Bug Fixes

3.0.2 (2025-01-23)

Bug Fixes

3.0.1 (2025-01-17)

Bug Fixes

  • isPermResultAuthorized fix (33a02cd)

3.0.0 (2025-01-17)

⚠ BREAKING CHANGES

  • check/request will now return a Status result instead of of an array

Bug Fixes

  • check/request will now return a Status result instead of of an array (e3651e5)

2.3.6 (2024-11-27)

Reverts

  • Revert "fix!: check/request will now return a Status result instead of of an array" (48fc65e)

2.3.5 (2024-11-18)

⚠ BREAKING CHANGES

  • check/request will now return a Status result instead of of an array

Features

  • openNotificationSettings (1f315e6)

Bug Fixes

  • check/request will now return a Status result instead of of an array (c4da3f1)
  • ios: openSettings not working in iOS 18 (9d5cf40)

2.3.4 (2024-10-23)

Bug Fixes

  • ios: prevent error in openSettings (f6536f2)

2.3.3 (2024-04-09)

Features

  • isPermResultAuthorized method (18b53c4)

2.3.2 (2024-03-08)

Bug Fixes

  • ios: location request would not resolve (2fe1edd)

2.3.1 (2024-01-11)

Bug Fixes

  • ios: more notification options (13266ab)
  • ios: Support Limited as a status for photo permissions (57a07ec)

2.3.0 (2023-03-02)

Bug Fixes

  • android: removed unwanted log (c6e154e)

Features

  • android: add granular permissions for accessing photo, video, and audio (747f6c8)

2.2.25 (2023-01-23)

Bug Fixes

  • improved native-api-usage (107750d)

2.2.24 (2023-01-19)

Bug Fixes

  • ios: check for multiple permissions fix (fd3c774)

2.2.23 (2023-01-17)

Bug Fixes

  • ios: correctly handle check/request for location with always type (a2bc977)

2.2.22 (2023-01-16)

Bug Fixes

2.2.21 (2022-12-09)

Bug Fixes

2.2.20 (2022-11-29)

Bug Fixes

  • rollback the issue was in the app (a9c636c)

2.2.19 (2022-11-29)

Bug Fixes

  • android: notifications permission on android 13 (a66e627)

2.2.18 (2022-11-29)

Bug Fixes

  • ios: anoher motion fix … (b8a8c1c)

2.2.17 (2022-11-29)

Bug Fixes

  • ios: motion permission fix (714ca67)

2.2.16 (2022-11-29)

Bug Fixes

2.2.15 (2022-11-29)

Bug Fixes

2.2.14 (2022-11-25)

Note: Version bump only for package @nativescript-community/perms

2.2.13 (2022-09-27)

Features

  • android: added notification(android13) and support for passing native permissions directly (00fb89e)

2.2.12 (2022-08-15)

Note: Version bump only for package @nativescript-community/perms

2.2.11 (2022-07-11)

Bug Fixes

  • ios: notifications ui thread handling (1b5abba)

2.2.10 (2022-07-11)

Bug Fixes

  • ios: notifications ui thread handling (1b5abba)

2.2.9 (2022-07-01)

Bug Fixes

2.2.8 (2022-06-30)

Bug Fixes

  • ios: notification perm status fix (0a082c6)

2.2.7 (2022-03-08)

Bug Fixes

  • android location precise option (3bdf6b8)

2.2.6 (2022-03-08)

Bug Fixes

  • allow to disable read/write for storage or coarse for location (461d499)

2.2.5 (2022-02-18)

Features

  • support requesting multiple perms on both platforms (a0bf946)

2.2.4 (2022-02-17)

Bug Fixes

  • android: fix for non know perms (08326d5)

2.2.3 (2022-02-17)

Features

  • android: allow to pass android permission(s) directly (1554882)
  • android: android 12 support: bluetooth(adv), bluetoothScan, bluetoothConnect, mediaLocation (08245c1)

2.2.2 (2022-01-10)

Bug Fixes

  • android: working openSettings (ccafa5c)

2.2.1 (2022-01-10)

Bug Fixes

  • androi: allow to open app settings (6b3dd9b)

2.2.0 (2021-10-21)

Bug Fixes

  • ios: handle new way of registering for notifcations on iOS >= 10 (f66ed95)

Features

  • android: native-api-usage (8ff8972)
  • ios: add ios12 notification providesAppNotificationSettings (551b225)

2.1.8 (2021-08-09)

Note: Version bump only for package @nativescript-community/perms

2.1.7 (2021-08-09)

Features

  • ios: add ios14 limited photo access permission status (83c0637)

2.1.6 (2021-04-27)

Bug Fixes

  • android: shouldShowRequestPermissionRationale fix for location (a402474)

2.1.5 (2021-01-13)

Bug Fixes

  • android: reject permission request on “cancel” (2f7661f)

2.1.4 (2020-11-23)

Note: Version bump only for package @nativescript-community/perms

2.1.3 (2020-11-22)

Note: Version bump only for package @nativescript-community/perms

2.1.2 (2020-11-17)

Bug Fixes

  • android always type support for location (4f1f521)

2.1.1 (2020-09-17)

Bug Fixes

  • ios: native class extend (b06738b)

2.1.0 (2020-09-06)

Features

2.0.11 (2020-05-29)

Note: Version bump only for package @nativescript-community/perms

2.0.10 (2020-05-21)

Note: Version bump only for package @nativescript-community/perms

2.0.9 (2020-05-21)

Bug Fixes

  • sideEffects for tree shacking (fb5ba26)

2.0.8 (2020-05-21)

Bug Fixes

  • esm using import for tree shaking (c0c1e7b)

2.0.7 (2020-05-21)

Note: Version bump only for package @nativescript-community/perms

2.0.6 (2020-04-05)

Bug Fixes

  • ios: improving fix (5903b46)
  • ios: trying to fix a crash with location permissions (e6eb678)

2.0.5 (2020-03-30)

Bug Fixes

2.0.4 (2020-03-24)

Bug Fixes

  • ios: video permission fix (9aa933f)

2.0.3 (2020-01-29)

Bug Fixes

  • android: return authorized like iOS (67a0015)

2.0.2 (2019-12-17)

Bug Fixes

2.0.1 (2019-12-16)

Note: Version bump only for package @nativescript-community/perms

2.0.0 (2019-12-16)

Bug Fixes

BREAKING CHANGES

  • return always in promises

1.0.10 (2019-10-22)

Bug Fixes

1.0.9 (2019-09-17)

Bug Fixes

1.0.8 (2019-08-15)

Bug Fixes

  • fixed motion permission (10a3ede)

1.0.7 (2019-05-17)

Bug Fixes

  • better logs (4610cfa)
  • keep a reference to the listener as long as we use it (c85e4f9)

1.0.6 (2019-05-16)

Bug Fixes

  • trying to fix crash on iOS. Not fully understood though (6aec74b)

1.0.5 (2019-05-04)

Bug Fixes

  • unhandled permissions should resolve not the break app (14f760a)