|
@@ -22,6 +22,12 @@ The current supported permissions are:
|
22
|
22
|
| 0.2.5 | 0.33.0 - 0.39.0 |
|
23
|
23
|
*Complies with [react-native-version-support-table](https://github.com/dangnelson/react-native-version-support-table)*
|
24
|
24
|
|
|
25
|
+### Breaking changes in version 1.0.0
|
|
26
|
+ - Now using React Native's own JS PermissionsAndroid library on Android, which is great because now we no longer have to do any additional linking (on Android)
|
|
27
|
+ - Updated API to be closer to RN's PermissionsAndroid
|
|
28
|
+ - Removed `openSettings()` support on Android (to stay linking-free). There are several NPM modules available for this
|
|
29
|
+ - `restricted` status now supported on Android, although it means something different than iOS
|
|
30
|
+
|
25
|
31
|
## General Usage
|
26
|
32
|
```
|
27
|
33
|
npm install --save react-native-permissions
|
|
@@ -36,7 +42,7 @@ const Permissions = require('react-native-permissions');
|
36
|
42
|
//...
|
37
|
43
|
//check the status of a single permission
|
38
|
44
|
componentDidMount() {
|
39
|
|
- Permissions.getPermissionStatus('photo')
|
|
45
|
+ Permissions.check('photo')
|
40
|
46
|
.then(response => {
|
41
|
47
|
//response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
|
42
|
48
|
this.setState({ photoPermission: response })
|
|
@@ -45,7 +51,7 @@ const Permissions = require('react-native-permissions');
|
45
|
51
|
|
46
|
52
|
//request permission to access photos
|
47
|
53
|
_requestPermission() {
|
48
|
|
- Permissions.requestPermission('photo')
|
|
54
|
+ Permissions.request('photo')
|
49
|
55
|
.then(response => {
|
50
|
56
|
//returns once the user has chosen to 'allow' or to 'not allow' access
|
51
|
57
|
//response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
|
|
@@ -55,7 +61,7 @@ const Permissions = require('react-native-permissions');
|
55
|
61
|
|
56
|
62
|
//check the status of multiple permissions
|
57
|
63
|
_checkCameraAndPhotos() {
|
58
|
|
- Permissions.checkMultiplePermissions(['camera', 'photo'])
|
|
64
|
+ Permissions.check(['camera', 'photo'])
|
59
|
65
|
.then(response => {
|
60
|
66
|
//response is an object mapping type to permission
|
61
|
67
|
this.setState({
|
|
@@ -118,18 +124,18 @@ Promises resolve into one of these statuses
|
118
|
124
|
### Methods
|
119
|
125
|
| Method Name | Arguments | Notes
|
120
|
126
|
|---|---|---|
|
121
|
|
-| `check` | `type` | - Returns a promise with the permission status. See iOS Notes for special cases |
|
122
|
|
-| `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|
|
123
|
|
-| `checkMultiple` | `[types]` | - Accepts an array of permission types and returns a promise with an object mapping permission types to statuses |
|
124
|
|
-| `getTypes` | *none* | - Returns an array of valid permission types |
|
125
|
|
-| `openSettings` | *none* | - *(iOS only - 8.0 and later)* Switches the user to the settings page of your app |
|
126
|
|
-| `canOpenSettings` | *none* | - *(iOS only)* Returns a boolean indicating if the device supports switching to the settings page |
|
|
127
|
+| `check()` | `type` | - Returns a promise with the permission status. See iOS Notes for special cases |
|
|
128
|
+| `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|
|
|
129
|
+| `checkMultiple()` | `[types]` | - Accepts an array of permission types and returns a promise with an object mapping permission types to statuses |
|
|
130
|
+| `getTypes()` | *none* | - Returns an array of valid permission types |
|
|
131
|
+| `openSettings()` | *none* | - *(iOS only - 8.0 and later)* Switches the user to the settings page of your app |
|
|
132
|
+| `canOpenSettings()` | *none* | - *(iOS only)* Returns a boolean indicating if the device supports switching to the settings page |
|
127
|
133
|
|
128
|
134
|
### iOS Notes
|
129
|
135
|
- Permission type `bluetooth` represents the status of the `CBPeripheralManager`. Don't use this if only need `CBCentralManager`
|
130
|
|
-- Permission type `location` accepts a second parameter for `requestPermission` and `getPermissionStatus`; the second parameter is a string, either `always` or `whenInUse`(default).
|
|
136
|
+- Permission type `location` accepts a second parameter for `request()` and `check()`; the second parameter is a string, either `always` or `whenInUse`(default).
|
131
|
137
|
|
132
|
|
-- Permission type `notification` accepts a second parameter for `requestPermission`. The second parameter is an array with the desired alert types. Any combination of `alert`, `badge` and `sound` (default requests all three)
|
|
138
|
+- 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)
|
133
|
139
|
|
134
|
140
|
```js
|
135
|
141
|
///example
|
|
@@ -163,9 +169,9 @@ Requires RN >= 0.29.0
|
163
|
169
|
|
164
|
170
|
Uses RN's own `PermissionsAndroid` JS api (http://facebook.github.io/react-native/releases/0.45/docs/permissionsandroid.html)
|
165
|
171
|
|
166
|
|
-All required permissions also need to be included in the Manifest before they can be requested. Otherwise `requestPermission` will immediately return `denied`.
|
|
172
|
+All required permissions also need to be included in the Manifest before they can be requested. Otherwise `request()` will immediately return `denied`.
|
167
|
173
|
|
168
|
|
-Permissions are automatically accepted for targetSdkVersion < 23 but you can still use `getPermissionStatus` to check if the user has disabled them from Settings.
|
|
174
|
+Permissions are automatically accepted for targetSdkVersion < 23 but you can still use `check()` to check if the user has disabled them from Settings.
|
169
|
175
|
|
170
|
176
|
You can request write access to any of these types by also including the appropriate write permission in the Manifest. Read more here: https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
|
171
|
177
|
|
|
@@ -204,6 +210,10 @@ So before submitting your app to the `AppStore`, make sure that in your `Info.pl
|
204
|
210
|
<string>Some description</string>
|
205
|
211
|
<key>NSPhotoLibraryUsageDescription</key>
|
206
|
212
|
<string>Some description</string>
|
|
213
|
+<key>NSPhotoLibraryUsageDescription</key>
|
|
214
|
+<string>Some description</string>
|
|
215
|
+<key>NSSpeechRecognitionUsageDescription</key>
|
|
216
|
+<string>Some description</string>
|
207
|
217
|
|
208
|
218
|
```
|
209
|
219
|
|