|
@@ -20,12 +20,12 @@ _Complies with
|
20
|
20
|
|
21
|
21
|
## ⚠️ Breaking changes in version 1.0.0
|
22
|
22
|
|
23
|
|
-* Now using React Native's own JS `PermissionsAndroid` module on Android, which
|
|
23
|
+- Now using React Native's own JS `PermissionsAndroid` module on Android, which
|
24
|
24
|
is great because we no longer have to do any additional linking on Android
|
25
|
|
-* Updated API to be closer to React Native's `PermissionsAndroid`
|
26
|
|
-* Removed `openSettings()` support on Android (to stay linking-free). There are
|
|
25
|
+- Updated API to be closer to React Native's `PermissionsAndroid`
|
|
26
|
+- Removed `openSettings()` support on Android (to stay linking-free). There are
|
27
|
27
|
several NPM modules available for this
|
28
|
|
-* `restricted` status now supported on Android, although it means something
|
|
28
|
+- `restricted` status now supported on Android, although it means something
|
29
|
29
|
different than iOS
|
30
|
30
|
|
31
|
31
|
## Setup
|
|
@@ -62,13 +62,12 @@ react-native link react-native-permissions
|
62
|
62
|
folder ➜ `Add Files to <...>`
|
63
|
63
|
2. Go to `node_modules` ➜ `react-native-permissions` ➜ select
|
64
|
64
|
`ReactNativePermissions.xcodeproj`
|
65
|
|
-3. Add `libReactNativePermissions.a` to `Build Phases` -> `Link Binary With
|
66
|
|
- Libraries`
|
|
65
|
+3. Add `libReactNativePermissions.a` to `Build Phases` -> `Link Binary With Libraries`
|
67
|
66
|
|
68
|
67
|
## Using
|
69
|
68
|
|
70
|
69
|
```js
|
71
|
|
-import Permissions from 'react-native-permissions'
|
|
70
|
+import Permissions from 'react-native-permissions';
|
72
|
71
|
// OR const Permissions = require('react-native-permissions').default
|
73
|
72
|
// if you use CommonJS module system
|
74
|
73
|
|
|
@@ -81,8 +80,8 @@ export default class extends React.Component {
|
81
|
80
|
componentDidMount() {
|
82
|
81
|
Permissions.check('photo').then(response => {
|
83
|
82
|
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
|
84
|
|
- this.setState({ photoPermission: response })
|
85
|
|
- })
|
|
83
|
+ this.setState({photoPermission: response});
|
|
84
|
+ });
|
86
|
85
|
}
|
87
|
86
|
|
88
|
87
|
// Request permission to access photos
|
|
@@ -90,9 +89,9 @@ export default class extends React.Component {
|
90
|
89
|
Permissions.request('photo').then(response => {
|
91
|
90
|
// Returns once the user has chosen to 'allow' or to 'not allow' access
|
92
|
91
|
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
|
93
|
|
- this.setState({ photoPermission: response })
|
94
|
|
- })
|
95
|
|
- }
|
|
92
|
+ this.setState({photoPermission: response});
|
|
93
|
+ });
|
|
94
|
+ };
|
96
|
95
|
|
97
|
96
|
// Check the status of multiple permissions
|
98
|
97
|
_checkCameraAndPhotos = () => {
|
|
@@ -101,9 +100,9 @@ export default class extends React.Component {
|
101
|
100
|
this.setState({
|
102
|
101
|
cameraPermission: response.camera,
|
103
|
102
|
photoPermission: response.photo,
|
104
|
|
- })
|
105
|
|
- })
|
106
|
|
- }
|
|
103
|
+ });
|
|
104
|
+ });
|
|
105
|
+ };
|
107
|
106
|
|
108
|
107
|
// This is a common pattern when asking for permissions.
|
109
|
108
|
// iOS only gives you once chance to show the permission dialog,
|
|
@@ -122,10 +121,10 @@ export default class extends React.Component {
|
122
|
121
|
style: 'cancel',
|
123
|
122
|
},
|
124
|
123
|
this.state.photoPermission == 'undetermined'
|
125
|
|
- ? { text: 'OK', onPress: this._requestPermission }
|
126
|
|
- : { text: 'Open Settings', onPress: Permissions.openSettings },
|
|
124
|
+ ? {text: 'OK', onPress: this._requestPermission}
|
|
125
|
+ : {text: 'Open Settings', onPress: Permissions.openSettings},
|
127
|
126
|
],
|
128
|
|
- )
|
|
127
|
+ );
|
129
|
128
|
}
|
130
|
129
|
|
131
|
130
|
//...
|
|
@@ -141,7 +140,7 @@ Promises resolve into one of these statuses:
|
141
|
140
|
| Return value | Notes |
|
142
|
141
|
| -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
143
|
142
|
| `authorized` | User has authorized this permission |
|
144
|
|
-| `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' |
|
|
143
|
+| `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' |
|
145
|
144
|
| `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 |
|
146
|
145
|
| `undetermined` | User has not yet been prompted with a permission dialog |
|
147
|
146
|
|
|
@@ -182,40 +181,39 @@ The current supported permissions are:
|
182
|
181
|
|
183
|
182
|
### iOS Notes
|
184
|
183
|
|
185
|
|
-* Permission type `bluetooth` represents the status of the
|
|
184
|
+- Permission type `bluetooth` represents the status of the
|
186
|
185
|
`CBPeripheralManager`. Don't use this if you only need `CBCentralManager`.
|
187
|
|
-* Permission type `location` accepts a second parameter for `request()` and
|
|
186
|
+- Permission type `location` accepts a second parameter for `request()` and
|
188
|
187
|
`check()`; the second parameter is a string, either `always` or `whenInUse`
|
189
|
188
|
(default).
|
190
|
|
-* Permission type `notification` accepts a second parameter for `request()`. The
|
|
189
|
+- Permission type `notification` accepts a second parameter for `request()`. The
|
191
|
190
|
second parameter is an array with the desired alert types. Any combination of
|
192
|
191
|
`alert`, `badge` and `sound` (default requests all three).
|
193
|
|
-* If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project.
|
|
192
|
+- If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project.
|
194
|
193
|
|
195
|
194
|
```js
|
196
|
195
|
// example
|
197
|
|
-Permissions.check('location', { type: 'always' }).then(response => {
|
198
|
|
- this.setState({ locationPermission: response })
|
199
|
|
-})
|
|
196
|
+Permissions.check('location', {type: 'always'}).then(response => {
|
|
197
|
+ this.setState({locationPermission: response});
|
|
198
|
+});
|
200
|
199
|
|
201
|
|
-Permissions.request('location', { type: 'always' }).then(response => {
|
202
|
|
- this.setState({ locationPermission: response })
|
203
|
|
-})
|
|
200
|
+Permissions.request('location', {type: 'always'}).then(response => {
|
|
201
|
+ this.setState({locationPermission: response});
|
|
202
|
+});
|
204
|
203
|
|
205
|
|
-Permissions.request('notification', { type: ['alert', 'badge'] }).then(
|
|
204
|
+Permissions.request('notification', {type: ['alert', 'badge']}).then(
|
206
|
205
|
response => {
|
207
|
|
- this.setState({ notificationPermission: response })
|
|
206
|
+ this.setState({notificationPermission: response});
|
208
|
207
|
},
|
209
|
|
-)
|
|
208
|
+);
|
210
|
209
|
```
|
211
|
210
|
|
212
|
|
-* You cannot request microphone permissions on the simulator.
|
213
|
|
-* With Xcode 8, you now need to add usage descriptions for each permission you
|
|
211
|
+- You cannot request microphone permissions on the simulator.
|
|
212
|
+- With Xcode 8, you now need to add usage descriptions for each permission you
|
214
|
213
|
will request. Open Xcode ➜ `Info.plist` ➜ Add a key (starting with "Privacy -
|
215
|
214
|
...") with your kit specific permission.
|
216
|
215
|
|
217
|
|
-Example: If you need Contacts permission you have to add the key `Privacy -
|
218
|
|
-Contacts Usage Description`.
|
|
216
|
+Example: If you need Contacts permission you have to add the key `Privacy - Contacts Usage Description`.
|
219
|
217
|
|
220
|
218
|
<img width="338" alt="3cde3b44-7ffd-11e6-918b-63888e33f983" src="https://cloud.githubusercontent.com/assets/1440796/18713019/271be540-8011-11e6-87fb-c3828c172dfc.png">
|
221
|
219
|
|
|
@@ -248,6 +246,7 @@ So before submitting your app to the App Store, make sure that in your
|
248
|
246
|
<key>NSMotionUsageDescription</key>
|
249
|
247
|
<string>Some description</string>
|
250
|
248
|
```
|
|
249
|
+
|
251
|
250
|
This is required because during the phase of processing in the App Store
|
252
|
251
|
submission, the system detects that you app contains code to request the
|
253
|
252
|
permission `X` but don't have the `UsageDescription` key and then it rejects the
|
|
@@ -260,16 +259,16 @@ You can find more information about this issue in #46.
|
260
|
259
|
|
261
|
260
|
### Android Notes
|
262
|
261
|
|
263
|
|
-* Uses React Native's own
|
|
262
|
+- Uses React Native's own
|
264
|
263
|
[`PermissionsAndroid` JS API](http://facebook.github.io/react-native/docs/permissionsandroid.html).
|
265
|
|
-* All required permissions also need to be included in the `AndroidManifest.xml`
|
|
264
|
+- All required permissions also need to be included in the `AndroidManifest.xml`
|
266
|
265
|
file before they can be requested. Otherwise `request()` will immediately
|
267
|
266
|
return `denied`.
|
268
|
|
-* You can request write access to any of these types by also including the
|
|
267
|
+- You can request write access to any of these types by also including the
|
269
|
268
|
appropriate write permission in the `AndroidManifest.xml` file. Read more
|
270
|
269
|
[here](https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous).
|
271
|
270
|
|
272
|
|
-* The optional rationale argument will show a dialog prompt.
|
|
271
|
+- The optional rationale argument will show a dialog prompt.
|
273
|
272
|
|
274
|
273
|
```js
|
275
|
274
|
// example
|
|
@@ -281,11 +280,11 @@ Permissions.request('camera', {
|
281
|
280
|
'so you can take awesome pictures.',
|
282
|
281
|
},
|
283
|
282
|
}).then(response => {
|
284
|
|
- this.setState({ cameraPermission: response })
|
285
|
|
-})
|
|
283
|
+ this.setState({cameraPermission: response});
|
|
284
|
+});
|
286
|
285
|
```
|
287
|
286
|
|
288
|
|
-* Permissions are automatically accepted for **targetSdkVersion < 23** but you
|
|
287
|
+- Permissions are automatically accepted for **targetSdkVersion < 23** but you
|
289
|
288
|
can still use `check()` to check if the user has disabled them from Settings.
|
290
|
289
|
|
291
|
290
|
You might need to elevate the **targetSdkVersion** version in your
|