Skip to content

Commit

Permalink
fix: request image access permissions for iOS only for native image p…
Browse files Browse the repository at this point in the history
…icking
  • Loading branch information
khushal87 committed Sep 18, 2024
1 parent 3497bcb commit eb69774
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions package/expo-package/src/optionalDependencies/pickImage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Platform } from 'react-native';
let ImagePicker;

try {
Expand All @@ -15,15 +16,18 @@ if (!ImagePicker) {
export const pickImage = ImagePicker
? async () => {
try {
const permissionCheck = await ImagePicker.getMediaLibraryPermissionsAsync();
const canRequest = permissionCheck.canAskAgain;
let permissionGranted = permissionCheck.granted;
if (!permissionGranted) {
if (canRequest) {
const response = await ImagePicker.requestMediaLibraryPermissionsAsync();
permissionGranted = response.granted;
} else {
return { askToOpenSettings: true, cancelled: true };
let permissionGranted = true;
if (Platform.OS === 'ios') {
const permissionCheck = await ImagePicker.getMediaLibraryPermissionsAsync();
const canRequest = permissionCheck.canAskAgain;
permissionGranted = permissionCheck.granted;
if (!permissionGranted) {
if (canRequest) {
const response = await ImagePicker.requestMediaLibraryPermissionsAsync();
permissionGranted = response.granted;
} else {
return { askToOpenSettings: true, cancelled: true };
}
}
}
if (permissionGranted) {
Expand Down

0 comments on commit eb69774

Please sign in to comment.