diff --git a/package/native-package/src/handlers/takePhoto.ts b/package/native-package/src/handlers/takePhoto.ts index 72d02acd0e..928a278037 100644 --- a/package/native-package/src/handlers/takePhoto.ts +++ b/package/native-package/src/handlers/takePhoto.ts @@ -1,8 +1,6 @@ import { AppState, Image, Linking, PermissionsAndroid, Platform } from 'react-native'; import ImagePicker from 'react-native-image-crop-picker'; -let hadDeniedAndroidPermission = false; - export const takePhoto = async ({ compressImageQuality = Platform.OS === 'ios' ? 0.8 : 1 }) => { if (Platform.OS === 'android') { const cameraPermissions = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA); @@ -11,12 +9,9 @@ export const takePhoto = async ({ compressImageQuality = Platform.OS === 'ios' ? PermissionsAndroid.PERMISSIONS.CAMERA, ); if (androidPermissionStatus === PermissionsAndroid.RESULTS.DENIED) { - hadDeniedAndroidPermission = true; return { cancelled: true }; } else if (androidPermissionStatus === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) { - if (!hadDeniedAndroidPermission) { - Linking.openSettings(); - } + Linking.openSettings(); return { cancelled: true }; } } @@ -62,9 +57,15 @@ export const takePhoto = async ({ compressImageQuality = Platform.OS === 'ios' ? }; } } catch (e: unknown) { - // on iOS: if it was in inactive state, then the user had just denied the permissions - if (Platform.OS === 'ios' && AppState.currentState === 'active') { - await Linking.openSettings(); + if (e instanceof Error) { + // on iOS: if it was in inactive state, then the user had just denied the permissions + if (Platform.OS === 'ios' && AppState.currentState === 'active') { + const cameraPermissionDeniedMsg = 'User did not grant camera permission.'; + // Open settings when the user did not allow camera permissions + if (e.message === cameraPermissionDeniedMsg) { + await Linking.openSettings(); + } + } } }