I have an app that allows users to take photos and then their location and time the photo was taken at are stored. Works fine for Android users but in iOS the photo is just never visible after being taken.
I am new to ionic and Angular so please any advice is welcome. Important to note it does not work whether in offline mode or not and it does work in the iOS simulator!
public async addNewToGallery(startEnd: string, user_ID: string, trainingID: string, isOnline: boolean) {
console.log("Adding new photo to gallery...");
this.sessionUUID = trainingID;
const loading = await this.loadingController.create({
message: 'Please wait...'
});
await loading.present();
try {
let capturedPhoto: Photo | null = null;
console.log("Capturing photo...");
capturedPhoto = await this.captureNewPhoto();
if (!capturedPhoto) {
throw new Error('Failed to capture or load photo');
}
// Save the picture to disk
const savedImageFile = await this.savePicture(capturedPhoto, startEnd);
let coordinates;
if (isOnline) {
coordinates = await this.getCoordinates();
} else {
coordinates = await this.geocodingService.getCurrentPosition();
}
if(coordinates)
{
this.latitude = coordinates.latitude;
this.longitude = coordinates.longitude;
}
else
{
this.latitude = 0;
this.longitude = 0;
coordinates = { latitude: 0, longitude: 0 };
}
this.placename = isOnline ? await this.getPlacename(coordinates) : 'Offline';
console.log(this.placename, "PLACENAME");
let peopleCount = 0;
if (isOnline) {
if (capturedPhoto.webPath) {
//const image = await this.createImageFromPath(capturedPhoto.webPath);
//peopleCount = await this.countPeopleInImage(image);
//console.log(peopleCount, "PEOPLE COUNT", image, "IMAGE");
} else {
throw new Error('Web path is undefined');
}
}
const photoObject = await this.createPhotoObject(savedImageFile, coordinates, this.placename, peopleCount);
photoObject.webviewPath = capturedPhoto.webPath;
if (startEnd === "start") {
this.startPhoto = photoObject;
this.startPhotoUrl = capturedPhoto?.webPath ?? '';
} else {
this.endPhoto = photoObject;
this.endPhotoUrl = capturedPhoto?.webPath ?? '';
}
if (isOnline) {
console.log("Performing online operations");
console.log(user_ID, "USERID", trainingID, "TRAININGID", startEnd, "STARTEND", photoObject, "PHOTOOBJECT");
await this.performOnlineOperations(user_ID, trainingID, startEnd, photoObject);
}
} catch (error) {
console.error('Error in addNewToGallery:', error);
throw error;
} finally {
await loading.dismiss();
}
}
private async captureNewPhoto(): Promise<Photo> {
try {
const photo = await Camera.getPhoto({
resultType: CameraResultType.Uri,
source: CameraSource.Camera,
quality: 100
});
return photo;
} catch (error) {
console.error('Error capturing photo:', error);
throw error;
}
}
1 post - 1 participant