forked from HugoGresse/react-native-issue-30277
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.js
42 lines (41 loc) · 1.39 KB
/
permissions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { check, request, RESULTS } from 'react-native-permissions';
export const requireExtStoragePermissionIfNeeded = async (permissionName) => {
if(Platform.OS === "ios") {
return true
}
// Request permissions to display images if needed:
return check(permissionName)
.then(result => {
switch (result) {
case RESULTS.GRANTED:
case RESULTS.UNAVAILABLE:
return true
case RESULTS.DENIED:
case RESULTS.BLOCKED:
console.log(
'The read ext storage permission is not granted',
);
return false
}
})
.then(granted => {
if(!granted) {
return request(permissionName)
.then(result => {
switch (result) {
case RESULTS.GRANTED:
case RESULTS.UNAVAILABLE:
return true
case RESULTS.DENIED:
case RESULTS.BLOCKED:
return false
}
})
}
return true
})
.catch(error => {
console.log("Failed to grant permission", error);
return false
});
}