|
2 | 2 |
|
3 | 3 | [](https://badge.fury.io/js/react-native-permissions) |
4 | 4 | [](https://www.npmjs.org/package/react-native-permissions) |
5 | | - |
| 5 | + |
6 | 6 |  |
7 | 7 | [](https://github.com/prettier/prettier) |
8 | 8 |
|
9 | | -A unified permissions API for React Native on iOS and Android. |
| 9 | +A unified permissions API for React Native on iOS, Android and Windows. |
| 10 | + |
| 11 | +For Windows only builds 18362 and later are supported. |
10 | 12 |
|
11 | 13 | ## Support |
12 | 14 |
|
13 | | -| version | react-native version | |
14 | | -| ------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | |
15 | | -| 2.0.0+ | 0.60.2+ | |
| 15 | +| version | react-native version | |
| 16 | +| ------- | -------------------- | |
| 17 | +| 2.0.0+ | 0.60.2+ | |
16 | 18 |
|
17 | 19 | ## Setup |
18 | 20 |
|
@@ -173,9 +175,13 @@ Add all wanted permissions to your app `android/app/src/main/AndroidManifest.xml |
173 | 175 | </manifest> |
174 | 176 | ``` |
175 | 177 |
|
| 178 | +### Windows |
| 179 | + |
| 180 | +Open the project solution file from the `windows` folder. In the app project open `Package.appxmanifest` file. From there you can select which capabilites you want your app to support. |
| 181 | + |
176 | 182 | ## 🆘 Manual linking |
177 | 183 |
|
178 | | -Because this package targets React Native 0.60.0+, you probably won't need to link it manually. Otherwise if it's not the case, follow these additional instructions: |
| 184 | +Because this package targets React Native 0.60.0+, you probably won't need to link it manually. Otherwise if it's not the case, follow these additional instructions. You also need to manual link the module on Windows when using React Native Windows prior to 0.63: |
179 | 185 |
|
180 | 186 | <details> |
181 | 187 | <summary><b>👀 See manual linking instructions</b></summary> |
@@ -231,6 +237,23 @@ public class MainApplication extends Application implements ReactApplication { |
231 | 237 | } |
232 | 238 | ``` |
233 | 239 |
|
| 240 | +### Windows |
| 241 | + |
| 242 | +1. In `windows/myapp.sln` add the `RNCConfig` project to your solution: |
| 243 | + |
| 244 | + - Open the solution in Visual Studio 2019 |
| 245 | + - Right-click Solution icon in Solution Explorer > Add > Existing Project |
| 246 | + - Select `node_modules\react-native-permissions\windows\RNPermissions\RNPermissions.vcxproj` |
| 247 | + |
| 248 | +2. In `windows/myapp/myapp.vcxproj` ad a reference to `RNPermissions` to your main application project. From Visual Studio 2019: |
| 249 | + |
| 250 | + - Right-click main application project > Add > Reference... |
| 251 | + - Check `RNPermissions` from Solution Projects. |
| 252 | + |
| 253 | +3. In `pch.h` add `#include "winrt/RNPermissions.h"`. |
| 254 | + |
| 255 | +4. In `app.cpp` add `PackageProviders().Append(winrt::RNPermissions::ReactPackageProvider());` before `InitializeComponent();`. |
| 256 | + |
234 | 257 | </details> |
235 | 258 |
|
236 | 259 | ## Understanding permission flow |
@@ -337,6 +360,56 @@ As permissions are not handled in the same way on iOS and Android, this library |
337 | 360 | └─────────────────┘ └─────────────────┘ |
338 | 361 | ``` |
339 | 362 |
|
| 363 | +### Windows flow |
| 364 | + |
| 365 | +``` |
| 366 | + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 367 | + ┃ check(PERMISSIONS.WINDOWS.WEBCAM) ┃ |
| 368 | + ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 369 | + │ |
| 370 | + Is the feature available |
| 371 | + on this device ? |
| 372 | + │ ╔════╗ |
| 373 | + ├───────────║ NO ║──────────────┐ |
| 374 | + │ ╚════╝ │ |
| 375 | + ╔═════╗ ▼ |
| 376 | + ║ YES ║ ┌─────────────────────┐ |
| 377 | + ╚═════╝ │ RESULTS.UNAVAILABLE │ |
| 378 | + │ └─────────────────────┘ |
| 379 | + Is the permission |
| 380 | + requestable ? |
| 381 | + │ ╔════╗ |
| 382 | + ├───────────║ NO ║──────────────┐ |
| 383 | + │ ╚════╝ │ |
| 384 | + ╔═════╗ ▼ |
| 385 | + ║ YES ║ ┌───────────────────┐ |
| 386 | + ╚═════╝ │ RESULTS.BLOCKED / │ |
| 387 | + │ │ RESULTS.GRANTED │ |
| 388 | + ▼ └───────────────────┘ |
| 389 | + ┌────────────────┐ |
| 390 | + │ RESULTS.DENIED │ |
| 391 | + └────────────────┘ |
| 392 | + │ |
| 393 | + ▼ |
| 394 | + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ |
| 395 | + ┃ request(PERMISSIONS.WINDOWS.WEBCAM) ┃ |
| 396 | + ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ |
| 397 | + │ |
| 398 | + Does the user accept |
| 399 | + the request ? |
| 400 | + │ ╔════╗ |
| 401 | + ├───────────║ NO ║──────────────┐ |
| 402 | + │ ╚════╝ │ |
| 403 | + ╔═════╗ ▼ |
| 404 | + ║ YES ║ ┌─────────────────┐ |
| 405 | + ╚═════╝ │ RESULTS.BLOCKED │ |
| 406 | + │ └─────────────────┘ |
| 407 | + ▼ |
| 408 | + ┌─────────────────┐ |
| 409 | + │ RESULTS.GRANTED │ |
| 410 | + └─────────────────┘ |
| 411 | +``` |
| 412 | + |
340 | 413 | ## API |
341 | 414 |
|
342 | 415 | ### Supported permissions |
@@ -394,6 +467,38 @@ PERMISSIONS.IOS.REMINDERS; |
394 | 467 | PERMISSIONS.IOS.SIRI; |
395 | 468 | PERMISSIONS.IOS.SPEECH_RECOGNITION; |
396 | 469 | PERMISSIONS.IOS.STOREKIT; |
| 470 | + |
| 471 | +// Windows permissions |
| 472 | + |
| 473 | +PERMISSIONS.WINDOWS.APPOINTMENTS; |
| 474 | +PERMISSIONS.WINDOWS.BLOCKED_CHAT_MESSAGES; |
| 475 | +PERMISSIONS.WINDOWS.BLUETOOTH_GATT; |
| 476 | +PERMISSIONS.WINDOWS.BLUETOOTH_RFCOMM; |
| 477 | +PERMISSIONS.WINDOWS.CHAT; |
| 478 | +PERMISSIONS.WINDOWS.CODE_GENERATION; |
| 479 | +PERMISSIONS.WINDOWS.CONTACTS; |
| 480 | +PERMISSIONS.WINDOWS.DOCUMENTS_LIBRARY; |
| 481 | +PERMISSIONS.WINDOWS.ENTERPRISE_AUTHENTICATION; |
| 482 | +PERMISSIONS.WINDOWS.HUMAN_INTERFACE_DEVICE; |
| 483 | +PERMISSIONS.WINDOWS.INTERNET_CLIENT; |
| 484 | +PERMISSIONS.WINDOWS.INTERNET_CLIENT_SERVER; |
| 485 | +PERMISSIONS.WINDOWS.LOCATION; |
| 486 | +PERMISSIONS.WINDOWS.MICROPHONE; |
| 487 | +PERMISSIONS.WINDOWS.MUSIC_LIBRARY; |
| 488 | +PERMISSIONS.WINDOWS.OBJECTS_3D; |
| 489 | +PERMISSIONS.WINDOWS.PHONE_CALL; |
| 490 | +PERMISSIONS.WINDOWS.PHOTO_LIBRARY; |
| 491 | +PERMISSIONS.WINDOWS.POINT_OF_SERVICE; |
| 492 | +PERMISSIONS.WINDOWS.PRIVATE_NETWORK_CLIENT_SERVER; |
| 493 | +PERMISSIONS.WINDOWS.PROXIMITY; |
| 494 | +PERMISSIONS.WINDOWS.RECORDED_CALLS_FOLDER; |
| 495 | +PERMISSIONS.WINDOWS.REMOVABLE_STORAGE; |
| 496 | +PERMISSIONS.WINDOWS.SHARED_USER_CERTIFICATES; |
| 497 | +PERMISSIONS.WINDOWS.USB; |
| 498 | +PERMISSIONS.WINDOWS.USER_ACCOUNT_INFORMATION; |
| 499 | +PERMISSIONS.WINDOWS.VIDEOS_LIBRARY; |
| 500 | +PERMISSIONS.WINDOWS.VOIP_CALL; |
| 501 | +PERMISSIONS.WINDOWS.WEBCAM; |
397 | 502 | ``` |
398 | 503 |
|
399 | 504 | ### Permissions statuses |
@@ -519,6 +624,8 @@ checkNotifications().then(({status, settings}) => { |
519 | 624 |
|
520 | 625 | Request notifications permission status and get notifications settings values. |
521 | 626 |
|
| 627 | +You cannot request notifications permissions on Windows. Disabling or enabling notifications can only be done through the App Settings. |
| 628 | + |
522 | 629 | ```ts |
523 | 630 | // only used on iOS |
524 | 631 | type NotificationOption = |
@@ -637,6 +744,7 @@ request( |
637 | 744 | Platform.select({ |
638 | 745 | android: PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION, |
639 | 746 | ios: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE, |
| 747 | + windows: PERMISSIONS.WINDOWS.LOCATION, |
640 | 748 | }), |
641 | 749 | ); |
642 | 750 | ``` |
0 commit comments