markrachapoom
markrachapoom

Reputation: 23

undefined is not an object (evaluating '_ExponentImagePicker.default.requestMediaLibraryPermissionsAsync') in expo-image-picker

Error from catch error block Image

Hi, I am using expo-image-picker and I stumbled with this error for a while now. and this is all the necessary code that I use. I'll give a green checkmark for appreciation.

For more information, I have already handled the permission in info.plist.

// Camera & Image Picker
import * as ImagePicker from 'expo-image-picker';

const openImagePicker = async () => {
    try {
        // Ask the user for the permission to access the media library 

        const permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync()


        if (permissionResult.granted === false) {
            alert("You've refused to allow this appp to access your photos!");
            return;
        } 

        const result = await ImagePicker.launchImageLibraryAsync();

        // Explore the result
        console.log(result);

        if (result.cancelled === false) {
            setPickedImagePath(result.uri);
            console.log(result.uri);
        }
    } catch (error) {
        alert('Error Occur: ' + error.message)
        closeSheet()
    }
}

Upvotes: 2

Views: 1145

Answers (1)

Phobos
Phobos

Reputation: 1646

If you are using SDK 44, a permission request is no longer necessary for launching the image picker so you can remove the related code.

Simply call

const result = await ImagePicker.launchImageLibraryAsync({});

If you really want to ask for permission (which as I said is no longer necessary) the correct method is

ImagePicker.getMediaLibraryPermissionsAsync()

and not

ImagePicker.requestMediaLibraryPermissionsAsync()

Upvotes: 1

Related Questions