|
|
|
|
21
|
| 0.2.5 | 0.33.0 - 0.39.0 |
|
21
|
| 0.2.5 | 0.33.0 - 0.39.0 |
|
22
|
*Complies with [react-native-version-support-table](https://github.com/dangnelson/react-native-version-support-table)*
|
22
|
*Complies with [react-native-version-support-table](https://github.com/dangnelson/react-native-version-support-table)*
|
23
|
|
23
|
|
24
|
-##General Usage
|
|
|
|
|
24
|
+## General Usage
|
25
|
```
|
25
|
```
|
26
|
npm install --save react-native-permissions
|
26
|
npm install --save react-native-permissions
|
27
|
rnpm link
|
27
|
rnpm link
|
|
|
|
|
85
|
//...
|
85
|
//...
|
86
|
```
|
86
|
```
|
87
|
|
87
|
|
88
|
-##API
|
|
|
|
|
88
|
+## API
|
89
|
|
89
|
|
90
|
-###Permission statuses
|
|
|
|
|
90
|
+### Permission statuses
|
91
|
Promises resolve into one of these statuses
|
91
|
Promises resolve into one of these statuses
|
92
|
|
92
|
|
93
|
| Return value | Notes|
|
93
|
| Return value | Notes|
|
|
|
|
|
97
|
|`restricted`| *(iOS only)* 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. |
|
97
|
|`restricted`| *(iOS only)* 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. |
|
98
|
|`undetermined`| user has not yet been prompted with a permission dialog |
|
98
|
|`undetermined`| user has not yet been prompted with a permission dialog |
|
99
|
|
99
|
|
100
|
-###Supported permission types
|
|
|
|
|
100
|
+### Supported permission types
|
101
|
|
101
|
|
102
|
| Name | iOS | Android |
|
102
|
| Name | iOS | Android |
|
103
|
|---|---|---|
|
103
|
|---|---|---|
|
|
|
|
|
114
|
|`speechRecognition`| ✔️ | ❌ |
|
114
|
|`speechRecognition`| ✔️ | ❌ |
|
115
|
|`storage`| ❌️ | ✔ |
|
115
|
|`storage`| ❌️ | ✔ |
|
116
|
|
116
|
|
117
|
-###Methods
|
|
|
|
|
117
|
+### Methods
|
118
|
| Method Name | Arguments | Notes
|
118
|
| Method Name | Arguments | Notes
|
119
|
|---|---|---|
|
119
|
|---|---|---|
|
120
|
| `getPermissionStatus` | `type` | - Returns a promise with the permission status. See iOS Notes for special cases |
|
120
|
| `getPermissionStatus` | `type` | - Returns a promise with the permission status. See iOS Notes for special cases |
|
|
|
|
|
124
|
| `openSettings` | *none* | - Switches the user to the settings page of your app (iOS 8.0 and later) |
|
124
|
| `openSettings` | *none* | - Switches the user to the settings page of your app (iOS 8.0 and later) |
|
125
|
| `canOpenSettings` | *none* | - Returns a boolean indicating if the device supports switching to the settings page |
|
125
|
| `canOpenSettings` | *none* | - Returns a boolean indicating if the device supports switching to the settings page |
|
126
|
|
126
|
|
127
|
-###iOS Notes
|
|
|
|
|
127
|
+### iOS Notes
|
128
|
Permission type `bluetooth` represents the status of the `CBPeripheralManager`. Don't use this if only need `CBCentralManager`
|
128
|
Permission type `bluetooth` represents the status of the `CBPeripheralManager`. Don't use this if only need `CBCentralManager`
|
129
|
|
129
|
|
130
|
Permission type `location` accepts a second parameter for `requestPermission` and `getPermissionStatus`; the second parameter is a string, either `always` or `whenInUse`(default).
|
130
|
Permission type `location` accepts a second parameter for `requestPermission` and `getPermissionStatus`; the second parameter is a string, either `always` or `whenInUse`(default).
|
|
|
|
|
157
|
If you need Contacts permission you have to add the key "Privacy - Contacts Usage Description".
|
157
|
If you need Contacts permission you have to add the key "Privacy - Contacts Usage Description".
|
158
|
<img width="338" alt="3cde3b44-7ffd-11e6-918b-63888e33f983" src="https://cloud.githubusercontent.com/assets/1440796/18713019/271be540-8011-11e6-87fb-c3828c172dfc.png">
|
158
|
<img width="338" alt="3cde3b44-7ffd-11e6-918b-63888e33f983" src="https://cloud.githubusercontent.com/assets/1440796/18713019/271be540-8011-11e6-87fb-c3828c172dfc.png">
|
159
|
|
159
|
|
160
|
-###Android Notes
|
|
|
|
|
160
|
+### Android Notes
|
161
|
|
161
|
|
162
|
Requires RN >= 0.29.0
|
162
|
Requires RN >= 0.29.0
|
163
|
|
163
|
|
|
|
|
|
177
|
|
177
|
|
178
|
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
|
178
|
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
|
179
|
|
179
|
|
180
|
-##Setup
|
|
|
|
|
180
|
+## Setup
|
181
|
|
181
|
|
182
|
````
|
182
|
````
|
183
|
npm install --save react-native-permissions
|
183
|
npm install --save react-native-permissions
|
184
|
rnpm link
|
184
|
rnpm link
|
185
|
````
|
185
|
````
|
186
|
|
186
|
|
187
|
-###Or manualy linking
|
|
|
|
|
187
|
+### Or manualy linking
|
188
|
|
188
|
|
189
|
-####iOS
|
|
|
|
|
189
|
+#### iOS
|
190
|
* Run open node_modules/react-native-permissions
|
190
|
* Run open node_modules/react-native-permissions
|
191
|
* Drag ReactNativePermissions.xcodeproj into the Libraries group of your app's Xcode project
|
191
|
* Drag ReactNativePermissions.xcodeproj into the Libraries group of your app's Xcode project
|
192
|
* Add libReactNativePermissions.a to `Build Phases -> Link Binary With Libraries.
|
192
|
* Add libReactNativePermissions.a to `Build Phases -> Link Binary With Libraries.
|
193
|
|
193
|
|
194
|
-####Android
|
|
|
195
|
-#####Step 1 - Update Gradle Settings
|
|
|
|
|
194
|
+#### Android
|
|
|
195
|
+##### Step 1 - Update Gradle Settings
|
196
|
|
196
|
|
197
|
```
|
197
|
```
|
198
|
// file: android/settings.gradle
|
198
|
// file: android/settings.gradle
|
|
|
|
|
201
|
include ':react-native-permissions'
|
201
|
include ':react-native-permissions'
|
202
|
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
|
202
|
project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
|
203
|
```
|
203
|
```
|
204
|
-#####Step 2 - Update Gradle Build
|
|
|
|
|
204
|
+##### Step 2 - Update Gradle Build
|
205
|
|
205
|
|
206
|
```
|
206
|
```
|
207
|
// file: android/app/build.gradle
|
207
|
// file: android/app/build.gradle
|
|
|
|
|
212
|
compile project(':react-native-permissions')
|
212
|
compile project(':react-native-permissions')
|
213
|
}
|
213
|
}
|
214
|
```
|
214
|
```
|
215
|
-#####Step 3 - Register React Package
|
|
|
|
|
215
|
+##### Step 3 - Register React Package
|
216
|
```
|
216
|
```
|
217
|
...
|
217
|
...
|
218
|
import com.joshblour.reactnativepermissions.ReactNativePermissionsPackage; // <--- import
|
218
|
import com.joshblour.reactnativepermissions.ReactNativePermissionsPackage; // <--- import
|
|
|
|
|
233
|
}
|
233
|
}
|
234
|
```
|
234
|
```
|
235
|
|
235
|
|
236
|
-##Troubleshooting
|
|
|
|
|
236
|
+## Troubleshooting
|
237
|
|
237
|
|
238
|
#### Q: Android - `undefined is not a object (evaluating 'RNPermissions.requestPermissions')`
|
238
|
#### Q: Android - `undefined is not a object (evaluating 'RNPermissions.requestPermissions')`
|
239
|
A: `rnpm` may not have linked correctly. Follow the manual linking steps and make sure the library is linked
|
239
|
A: `rnpm` may not have linked correctly. Follow the manual linking steps and make sure the library is linked
|