I add Image Picker in React Native Expo its working fine on Android device however when upload image in iphone the app is close please do not down vote it and sorry for my english or I do not have iphone to test it is work or not many thanks
const pickImage = async () => {
const permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync();
if (permissionResult.granted === false) {
alert("You've refused to allow this app to access your photos!");
return;
}
const result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
console.log('ImagePicker result:', result);
if (!result.canceled) {
setImage(result.assets[0].uri);
console.log('Image selected:', result.assets[0].uri);
}
};
const uploadImage = async () => {
if (!image) {
alert('No image selected.');
return;
}
setUploading(true);
try {
const response = await fetch(image);
const blob = await response.blob();
const storage = getStorage();
const storageRef = ref(storage, `participationPhotos/${currentUser ? currentUser.userId : 'anonymous'}/${blob._data.name}`);
await uploadBytes(storageRef, blob);
const downloadURL = await getDownloadURL(storageRef);
console.log('Image uploaded:', downloadURL);
if (currentUser) {
// Update Firestore document
const db = getFirestore();
const userRef = doc(db, 'users', currentUser.userId);
await updateDoc(userRef, {
hasParticipatePhoto: true,
participatePhotoURL: downloadURL
});
console.log('Firestore updated with image URL.');
}
alert('Photo uploaded successfully!');
} catch (error) {
console.error('Error uploading photo:', error);
alert('Failed to upload photo. Please try again.');
} finally {
setUploading(false);
}
};
I need to work in both ios and android without crash