|
|
@@ -2,16 +2,16 @@
|
|
2
|
2
|
Request user permissions from React Native (iOS only - android coming soon)
|
|
3
|
3
|
|
|
4
|
4
|
The current supported permissions are:
|
|
5
|
|
-- Push Notifications
|
|
6
|
5
|
- Location
|
|
7
|
6
|
- Camera
|
|
8
|
7
|
- Microhone
|
|
9
|
8
|
- Photos
|
|
10
|
9
|
- Contacts
|
|
11
|
10
|
- Events
|
|
12
|
|
-- Reminders
|
|
13
|
|
-- Bluetooth (Peripheral role. Don't use for Central only)
|
|
14
|
|
-- Background Refresh
|
|
|
11
|
+- Reminders *(iOS only)*
|
|
|
12
|
+- Bluetooth *(iOS only)*
|
|
|
13
|
+- Push Notifications *(iOS only)*
|
|
|
14
|
+- Background Refresh *(iOS only)*
|
|
15
|
15
|
|
|
16
|
16
|
##General Usage
|
|
17
|
17
|
```js
|
|
|
@@ -72,10 +72,32 @@ const Permissions = require('react-native-permissions');
|
|
72
|
72
|
|
|
73
|
73
|
##API
|
|
74
|
74
|
|
|
75
|
|
-_Permission statuses_ - `authorized`, `denied`, `restricted`, or `undetermined`
|
|
|
75
|
+###Permission statuses
|
|
|
76
|
+Promises resolve into one of these statuses
|
|
76
|
77
|
|
|
77
|
|
-_Permission types_ - `location`, `camera`, `microphone`, `photo`, `contacts`, `event`, `reminder`, `bluetooth`, `notification`, or `backgroundRefresh`
|
|
|
78
|
+| Return value | Notes|
|
|
|
79
|
+|---|---|
|
|
|
80
|
+|`authorized`| user has authorized this permission |
|
|
|
81
|
+|`denied`| user has denied permissions at least once. On iOS this means that the user will not be prompted again. Android users can be promted multiple times until they select 'Never ask me again'|
|
|
|
82
|
+|`restricted`| iOS only|
|
|
|
83
|
+|`undetermined`| user has not yet been prompted with a permission dialog |
|
|
78
|
84
|
|
|
|
85
|
+###Supported permission types
|
|
|
86
|
+
|
|
|
87
|
+| Name | iOS | Android |
|
|
|
88
|
+|---|---|---|
|
|
|
89
|
+|`location`| ✔️ | ✔ |
|
|
|
90
|
+|`camera`| ✔️ | ✔ |
|
|
|
91
|
+|`microphone`| ✔️ | ✔ |
|
|
|
92
|
+|`photo`| ✔️ | ✔ |
|
|
|
93
|
+|`contacts`| ✔️ | ✔ |
|
|
|
94
|
+|`event`| ✔️ | ✔ |
|
|
|
95
|
+|`bluetooth`| ✔️ | ❌ |
|
|
|
96
|
+|`reminder`| ✔️ | ❌ |
|
|
|
97
|
+|`notification`| ✔️ | ❌ |
|
|
|
98
|
+|`backgroundRefresh`| ✔️ | ❌ |
|
|
|
99
|
+
|
|
|
100
|
+###Methods
|
|
79
|
101
|
| Method Name | Arguments | Notes
|
|
80
|
102
|
|---|---|---|
|
|
81
|
103
|
| `getPermissionStatus` | `type` | - Returns a promise with the permission status. Note: for type `location`, iOS `AuthorizedAlways` and `AuthorizedWhenInUse` both return `authorized` |
|
|
|
@@ -85,9 +107,8 @@ _Permission types_ - `location`, `camera`, `microphone`, `photo`, `contacts`, `e
|
|
85
|
107
|
| `openSettings` | *none* | - Switches the user to the settings page of your app (iOS 8.0 and later) |
|
|
86
|
108
|
| `canOpenSettings` | *none* | - Returns a boolean indicating if the device supports switching to the settings page |
|
|
87
|
109
|
|
|
88
|
|
-Note: Permission type `bluetooth` represents the status of the `CBPeripheralManager`. Don't use this if you're only using `CBCentralManager`
|
|
89
|
|
-
|
|
90
|
|
-###Special cases
|
|
|
110
|
+###iOS Notes
|
|
|
111
|
+Permission type `bluetooth` represents the status of the `CBPeripheralManager`. Don't use this if only need `CBCentralManager`
|
|
91
|
112
|
|
|
92
|
113
|
`requestPermission` also accepts a second parameter for types `location` and `notification`.
|
|
93
|
114
|
- `location`: the second parameter is a string, either `always` or `whenInUse`(default).
|
|
|
@@ -105,14 +126,73 @@ Note: Permission type `bluetooth` represents the status of the `CBPeripheralMana
|
|
105
|
126
|
})
|
|
106
|
127
|
```
|
|
107
|
128
|
|
|
|
129
|
+###Android Notes
|
|
|
130
|
+All required permissions also need to be included in the Manifest before they can be requested. Otherwise `requestPermission` will immediately return `denied`.
|
|
|
131
|
+
|
|
|
132
|
+Permissions are automatically accepted for targetSdkVersion < 23 but you can still use `getPermissionStatus` to check if the user has disabled them from Settings.
|
|
|
133
|
+
|
|
|
134
|
+Here's a map of types to Android system permissions names:
|
|
|
135
|
+`location` -> `android.permission.ACCESS_FINE_LOCATION`
|
|
|
136
|
+`camera` -> `android.permission.CAMERA`
|
|
|
137
|
+`microphone` -> `android.permission.RECORD_AUDIO`
|
|
|
138
|
+`photo` -> `android.permission.READ_EXTERNAL_STORAGE`
|
|
|
139
|
+`contacts` -> `android.permission.READ_CONTACTS`
|
|
|
140
|
+`event` -> `android.permission.READ_CALENDAR`
|
|
|
141
|
+
|
|
|
142
|
+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
|
|
108
|
143
|
|
|
109
|
144
|
##Setup
|
|
110
|
145
|
|
|
111
|
146
|
````
|
|
112
|
147
|
npm install --save react-native-permissions
|
|
|
148
|
+rnpm link
|
|
113
|
149
|
````
|
|
114
|
150
|
|
|
115
|
|
-##iOS
|
|
|
151
|
+###Or manualy linking
|
|
|
152
|
+
|
|
|
153
|
+####iOS
|
|
116
|
154
|
* Run open node_modules/react-native-permissions
|
|
117
|
155
|
* Drag ReactNativePermissions.xcodeproj into the Libraries group of your app's Xcode project
|
|
118
|
156
|
* Add libReactNativePermissions.a to `Build Phases -> Link Binary With Libraries.
|
|
|
157
|
+
|
|
|
158
|
+####Android
|
|
|
159
|
+#####Step 1 - Update Gradle Settings
|
|
|
160
|
+
|
|
|
161
|
+```
|
|
|
162
|
+// file: android/settings.gradle
|
|
|
163
|
+...
|
|
|
164
|
+
|
|
|
165
|
+include ':react-native-permissions'
|
|
|
166
|
+project(':react-native-permissions').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-permissions/android')
|
|
|
167
|
+```
|
|
|
168
|
+#####Step 2 - Update Gradle Build
|
|
|
169
|
+
|
|
|
170
|
+```
|
|
|
171
|
+// file: android/app/build.gradle
|
|
|
172
|
+...
|
|
|
173
|
+
|
|
|
174
|
+dependencies {
|
|
|
175
|
+ ...
|
|
|
176
|
+ compile project(':react-native-permissions')
|
|
|
177
|
+}
|
|
|
178
|
+```
|
|
|
179
|
+#####Step 3 - Register React Package
|
|
|
180
|
+```
|
|
|
181
|
+...
|
|
|
182
|
+import com.joshblour.reactnativepermissions.ReactNativePermissionsPackage; // <--- import
|
|
|
183
|
+
|
|
|
184
|
+public class MainActivity extends ReactActivity {
|
|
|
185
|
+
|
|
|
186
|
+ ...
|
|
|
187
|
+
|
|
|
188
|
+ @Override
|
|
|
189
|
+ protected List<ReactPackage> getPackages() {
|
|
|
190
|
+ return Arrays.<ReactPackage>asList(
|
|
|
191
|
+ new MainReactPackage(),
|
|
|
192
|
+ new ReactNativePermissionsPackage() // <------ add the package
|
|
|
193
|
+ );
|
|
|
194
|
+ }
|
|
|
195
|
+
|
|
|
196
|
+ ...
|
|
|
197
|
+}
|
|
|
198
|
+```
|