why I deny image permission of expo go, but I can also pick image on my phone?
code as follow:
import { useEffect } from “react”;
import {
View,
StyleSheet,
Image,
TouchableWithoutFeedback,
Alert,
} from “react-native”;
import { MaterialCommunityIcons } from “@expo/vector-icons”;
import * as ImagePicker from “expo-image-picker”;
import colors from “…/config/colors”;
function ImageInput({ imageUri, onChangeImage }) {
useEffect(() => {
requestPermission();
}, );
const requestPermission = async () => {
const result = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (!result.granted) {
alert("You need to enable permission to access the library.");
} else {
console.log("granted is true.");
}
};
const handlePress = () => {
if (!imageUri) selectImage();
else
Alert.alert(“Delete”, “Are you sure you want to delete this image?”, [
{ text: “Yes”, onPress: () => onChangeImage(null) },
{ text: “No” },
]);
};
const selectImage = async () => {
try {
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 0.5,
});
if (!result.cancelled) {
onChangeImage(result.uri);
} else {
console.log(“User cancelled!”);
}
} catch (error) {
console.log(“Error reading an image:”, error);
}
};
return (
{!imageUri && (
)}
{imageUri && <Image source={{ uri: imageUri }} style={styles.image} />}
);
}
const styles = StyleSheet.create({
container: {
alignItems: “center”,
backgroundColor: colors.light,
borderRadius: 15,
height: 100,
justifyContent: “center”,
overflow: “hidden”,
width: 100,
},
image: {
width: “100%”,
height: “100%”,
},
});
export default ImageInput;