Last active
July 5, 2020 11:25
-
-
Save uddish/ca5f630c6c4ceff1517d86482bd80087 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
check, | |
request, | |
RESULTS, | |
requestMultiple, | |
} from 'react-native-permissions'; | |
// This function can be used anywhere as it supports multiple permissions. | |
// It checks for permissions and then requests for it. | |
export async function checkMultiplePermissions(permissions) { | |
let isPermissionGranted = false; | |
const statuses = await requestMultiple(permissions); | |
for (var index in permissions) { | |
if (statuses[permissions[index]] === RESULTS.GRANTED) { | |
isPermissionGranted = true; | |
} else { | |
isPermissionGranted = false; | |
break; | |
} | |
} | |
return isPermissionGranted; | |
} | |
// In case you want to check a single permission | |
export async function checkPermission(permission) { | |
var isPermissionGranted = false; | |
const result = await check(permission); | |
switch (result) { | |
case RESULTS.GRANTED: | |
isPermissionGranted = true; | |
break; | |
case RESULTS.DENIED: | |
isPermissionGranted = false; | |
break; | |
case RESULTS.BLOCKED: | |
isPermissionGranted = false; | |
break; | |
case RESULTS.UNAVAILABLE: | |
isPermissionGranted = false; | |
break; | |
} | |
return isPermissionGranted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment