Has anyone experienced Expo go app for react native crashing when trying to upload image to Firebase store?
This issue started when I updated my iPhone to ios16. I can say the issue is with ios16 because on another iPhone and ipad with ios15.7 there is no crashing. There is also no crashing with all android phones.
My code is below just in case to check
useEffect(() => {
const setImageFiles = async () => {
setUploading(true);
const timeStamp = new Date().toISOString();
if (postImage1) {
const firstFilename = await postImage1.substring(
postImage1.lastIndexOf('/') + 1
);
const filenameFirsImage = timeStamp + firstFilename;
setFirstImageFile(filenameFirsImage);
} else {
const secondFilename = await postImage2.substring(
postImage2.lastIndexOf('/') + 1
);
const filenameSecondImage = timeStamp + secondFilename;
setSecondImageFile(filenameSecondImage);
}
setUploading(false);
};
const unsubscribe = NetInfo.addEventListener((state) => {
if (!state.isConnected) {
setIsConnected(false);
Alert.alert('Network Error!', 'You are not connected to the internet');
}
});
setImageFiles();
unsubscribe();
}, []);
const uploadImage1ToStore = async () => {
setUploading(true);
const blob = await new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.onload = function () {
resolve(xhr.response);
};
xhr.onerror = function () {
reject(new TypeError('Network request failed'));
};
xhr.responseType = 'blob';
xhr.open('GET', postImage1, true);
xhr.send(null);
});
const ref = firebase.storage().ref().child(firstImageFile);
const snapshot = ref.put(blob);
snapshot.on(
firebase.storage.TaskEvent.STATE_CHANGED,
() => {},
(error) => {
setUploading(false);
Alert.alert(error.message);
blob.close();
return;
},
() => {
snapshot.snapshot.ref
.getDownloadURL()
.then((url) => {
setPostImage1Url(url);
})
.catch((error) => {
Alert.alert(error.message);
});
blob.close();
}
);
};