2.1.1 • Published 8 years ago

cordova-plugin-permissionScope v2.1.1

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
8 years ago

Twitter: @alexiskofman License Build Status

cordova-plugin-permissionScope

This plugin is a wrapper of the very helpful Swift framework PermissionScope. It defines a global PermissionScope object, which permits to requesting permissions from users.

Installation

cordova plugin add cordova-plugin-permissionScope --save

The iOS part is written in Swift and the Swift support plugin is configured as a dependency.

:warning: Because this plugin doesn't support Swift 3 at the moment, the following preference has to be added in your project :

<preference name="UseLegacySwiftLanguageVersion" value="true" />

Supported Platforms

  • iOS

Methods

PermissionScope.init(config, success, error)

Inits and customizes the dialog and all the alerts displayed from direct requests. If called without any parameter then the default config is restored.

The following properties are available:

PropertyComment
headerLabelHeader UILabel with the message "Hey, listen!" by default.
bodyLabelHeader UILabel with the message "We need a couple things\r\nbefore you get started." by default.
closeButtonTitleTitle for the close button. "Close" by default.
closeButtonTextColorHex color code for the close button's text color (ie: #cccccc).
closeOffsetOffset used to position the Close button (ie: {-200,0}).
permissionButtonTextColorHex color code for the permission buttons' text color (ie: #cccccc).
permissionButtonBorderColorHex color code for the permission buttons' border color (ie: #cccccc).
permissionButtonΒorderWidthBorder width for the permission buttons.
permissionButtonCornerRadiusCorner radius for the permission buttons.
permissionLabelColorHex color code for the permission labels' text color (ie: #cccccc).
authorizedButtonColorHex color code used for permission buttons with authorized status (ie: #cccccc).
unauthorizedButtonColorHex color code used for permission buttons with unauthorized status. By default, inverse of authorizedButtonColor (ie: #cccccc).
deniedAlertTitleTitle for the denied alert.
deniedAlertMessageMessage for the denied alert.
deniedCancelActionTitleTitle for the denied alert's cancel button. "OK" by default.
deniedDefaultActionTitleTitle for the denied alert's default button. "Show me" by default.
disabledAlertTitleTitle for the disabled alert.
disabledAlertMessageMessage for the disabled alert.
disabledCancelActionTitleTitle for the disabled alert's cancel button. "OK" by default.
disabledDefaultActionTitleTitle for the disabled alert's default button. "Show me" by default.

PermissionScope.show(success, error)

Displays the permissions dialog if permissions have to be approved else does nothing.

PermissionScope.add<TYPE>Permission(message, success, error)

The following methods permit to set up permissions asked from the dialog :

  • PermissionScope.addNotificationsPermission(message, success, error)
  • PermissionScope.addLocationInUsePermission(message, success, error)
  • PermissionScope.addLocationAlwaysPermission(message, success, error)
  • PermissionScope.addContactsPermission(message, success, error)
  • PermissionScope.addEventsPermission(message, success, error)
  • PermissionScope.addMicrophonePermission(message, success, error)
  • PermissionScope.addCameraPermission(message, success, error)
  • PermissionScope.addPhotosPermission(message, success, error)
  • PermissionScope.addRemindersPermission(message, success, error)
  • PermissionScope.addBluetoothPermission(message, success, error)
  • PermissionScope.addMotionPermission(message, success, error)

Message is a label displayed below the permission button. Its goal is to explain why a permission has to be approved.

PermissionScope.request<TYPE>Permission(success, error)

The following methods permit to check whether a particular permission has been granted else it displays an alert :

  • PermissionScope.requestNotificationsPermission(success, error)
  • PermissionScope.requestLocationInUsePermission(success, error)
  • PermissionScope.requestLocationAlwaysPermission(success, error)
  • PermissionScope.requestContactsPermission(success, error)
  • PermissionScope.requestEventsPermission(success, error)
  • PermissionScope.requestMicrophonePermission(success, error)
  • PermissionScope.requestCameraPermission(success, error)
  • PermissionScope.requestPhotosPermission(success, error)
  • PermissionScope.requestRemindersPermission(success, error)
  • PermissionScope.requestBluetoothPermission(success, error)
  • PermissionScope.requestMotionPermission(success, error)

Examples

PermissionScope.init({
  headerLabel: 'Hello',
  bodyLabel: 'Before you get started',
  closeButtonTextColor: '#cccccc',
  closeButtonTitle: 'Return',
  permissionButtonTextColor: '#30ab7d',
  permissionButtonBorderColor: '#30ab7d',
  closeOffset: '{-200, 0}',
  authorizedButtonColor: '#cccccc',
  unauthorizedButtonColor: '#c2262d',
  permissionButtonCornerRadius: '20',
  permissionLabelColor: '#ff5500',
  permissionButtonΒorderWidth: '5',
  deniedCancelActionTitle: 'Cancel',
  deniedDefaultActionTitle: 'Settings',
  deniedAlertTitle: 'Permission',
  deniedAlertMessage: 'Please enable all the permissions',
  disabledCancelActionTitle: 'Cancel',
  disabledDefaultActionTitle: 'Settings',
});

PermissionScope.addBluetoothPermission('Please enable access to your Bluetooth');
PermissionScope.addCameraPermission('Please enable access to your Camera');
PermissionScope.addPhotosPermission('Please enable access to your Photos');

PermissionScope.show();

The result could be something like this :

npm.io

Here is the default version :

npm.io

PermissionScope.init({
  denieddDefaultActionTitle: 'Settings'
});

PermissionScope.requestEventsPermission();

Here is what you should obtain if the permission has not been granted :

npm.io

App

An app is available in the tests/app folder and is generated from the Cordova Plugin TestFramework. It permits to launch auto tests and manual tests.

To install it, please follow these steps :

npm run install && cordova run --device