Skip to content

Latest commit

 

History

History

expo-permissions-nativescript-plugin

@nativescript-community/expo-permissions-nativescript-plugin

About

This is the NativeScript implementation of the Expo SDK's Permissions APIs.

  • For iOS, it installs the native iOS expo-permissions source as-is.
  • For Android, I've been unable to get the native Android expo-permissions source to compile (a complication of it being Kotlin-based), so it installs the native Android source from our fork, @nativescript-community/expo-permissions. However, even with that approach, I've been unable to get things working, so summarily Android support is not working for now.

It exposes the very same cross-platform TypeScript APIs as expo-permissions does – this was achieved largely by copy-pasting the TypeScript source files from expo-permissions.

Installation

npm install --save @unimodules/core expo-permissions unimodules-permissions-interface
ns plugin add @nativescript-community/expo-nativescript-adapter
ns plugin add @nativescript-community/expo-permissions-nativescript-plugin

Structure

expo-permissions-nativescript-plugin has the following peer dependencies:

Package

Native Module

Optional?

Purpose

iOS

Android

@unimodules/core

UMCore org.unimodules.core Mandatory Implements the platform-agnostic API for consuming Expo Unimodules.

@nativescript-community/expo-nativescript-adapter

UMNativeModulesProxy org.unimodules.adapters.nativescript Mandatory Adapts Expo Unimodules to NativeScript (and auto-installs the native modules for the above node module).

unimodules-permissions-interface

UMPermissionsInterface org.unimodules.interfaces.permissions Mandatory It's the interface that expo-permissions implements.

expo-permissions

EXPermissions expo.modules.permissions Mandatory Provides the Expo Permissions APIs.

@nativescript-community/expo-permissions-nativescript-plugin

Same as above (this auto-installs the native modules for the above node module).

Status

See Permissions in the Expo SDK API docs for full documentation.

API

Support

Comments

iOS

Android

usePermissions React hook

🚫 🚫 Has some kind of dependency on React Native. Won't boter implementing.

Everything else

Should just work! Note that Android support is pending implementation of expo-nativescript-adapter.

Usage

Again, see Permissions in the Expo SDK API docs for full documentation.

Note that you can only use expo-permissions-nativescript-plugin to check or request permissions for other Expo Unimodules that you have installed. So, for example, you wouldn't be able to use it to request Contacts permissions unless you also had expo-contacts-nativescript-plugin installed. That's just the way it works.

Also, before asking for any permission, just as with native app development, you will still need to have the corresponding property listed in the appropriate place in your app, for example:

  • (for iOS): App_Resources/iOS/Info.plist file, e.g. <key>NSContactsUsageDescription</key>
  • (for Android): App_Resources/Android/src/main/AndroidManifest.xml file, e.g. <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" />.

... otherwise, your app may immediately crash without explanation 🤕

These NativeScript Expo plugins will not enter these properties for you; it's your responsibility to add them! Remember that when developing NativeScript apps, you'll have to run a rebuild of the app (e.g. tns build ios) to copy your latest Info.plist or AndroidManifest.xml into the app bundle; it's not simply something that Webpack will do for you in watch mode (to my understanding).

License

MIT