chore: Adds docs for Android permissions (#202)
* Adds docs for Android permissions * Corrected typo's and imporovements * Include CLI as a case explicitly * Remove unexpected pasted lines
This commit is contained in:
parent
f8b2860a74
commit
d21584ae4e
40
README.md
40
README.md
|
@ -57,14 +57,21 @@ import CameraRoll from "@react-native-community/cameraroll";
|
|||
|
||||
### Permissions
|
||||
|
||||
**iOS**
|
||||
|
||||
The user's permission is required in order to access the Camera Roll on devices running iOS 10 or later. Add the `NSPhotoLibraryUsageDescription` key in your `Info.plist` with a string that describes how your app will use this data. This key will appear as `Privacy - Photo Library Usage Description` in Xcode.
|
||||
|
||||
If you are targeting devices running iOS 11 or later, you will also need to add the `NSPhotoLibraryAddUsageDescription` key in your `Info.plist`. Use this key to define a string that describes how your app will use this data. By adding this key to your `Info.plist`, you will be able to request write-only access permission from the user. If you try to save to the camera roll without this permission, your app will exit.
|
||||
|
||||
On Android permission is required to read the external storage. Add below line to your manifest to request this permission on app install.
|
||||
On Android permission is required to write in the external storage when saving to camera roll. Add below line to your manifest to request this permission on app install.
|
||||
**Android**
|
||||
|
||||
```
|
||||
Permission is required to read and write to the external storage.
|
||||
|
||||
On Expo, follow the guide [here](https://docs.expo.io/versions/latest/sdk/permissions/) for requesting the permission.
|
||||
|
||||
On react-native-cli or ejected apps, adding the following lines will add the capability for the app to request the permission. Find more info on Android Permissions [here](https://reactnative.dev/docs/permissionsandroid).
|
||||
|
||||
```xml
|
||||
<manifest>
|
||||
...
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
@ -73,6 +80,33 @@ On Android permission is required to write in the external storage when saving t
|
|||
<application>
|
||||
```
|
||||
|
||||
Then you have to explicitly ask for the permission
|
||||
|
||||
```javascript
|
||||
import { PermissionsAndroid, Platform } from "react-native";
|
||||
import CameraRoll from "@react-native-community/cameraroll";
|
||||
|
||||
async function hasAndroidPermission() {
|
||||
const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
|
||||
|
||||
const hasPermission = await PermissionsAndroid.check(permission);
|
||||
if (hasPermission) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const status = await PermissionsAndroid.request(permission);
|
||||
return status === 'granted';
|
||||
}
|
||||
|
||||
async function savePicture() {
|
||||
if (Platform.OS === "android" && !(await hasAndroidPermission())) {
|
||||
return;
|
||||
}
|
||||
|
||||
CameraRoll.saveToCameraRoll(tag, [type]);
|
||||
};
|
||||
```
|
||||
|
||||
### Methods
|
||||
|
||||
* [`save`](#save)
|
||||
|
|
Loading…
Reference in New Issue