Reputation: 43
So after recently updating dependencies including Xamarin Forms, I can no longer see saved images within our app in iOS. We use https://github.com/jamesmontemagno/MediaPlugin for adding/taking pictures and have even tried specific OS file writes to environment folder:
iOS specific for saving an image:
public string WriteFile(byte[] data)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var filePath = Path.Combine(path, CameraHelper.GenerateFileName());
File.WriteAllBytes(filePath, data);
return filePath;
}
The images are saved under an ID that changes after every app update. This obviously breaks our previous method as we saved the image path (which was always the same prior) in the tables and used that to show preview of the images.
Here is the new image path:
"/var/mobile/Containers/Data/Application/215E777E-A624-487E-B687-6647F8C0D1DC/Documents/01_18_2021_04_24_07_98524.jpg"
Old path:
/data/user/0/com.company.ourapp/files/Pictures/
Which essentially makes it impossible for us to see pictures taken from a previous build/version of the app. I have scoured Xamarin Forms/Essentials and Stack Overflow but no luck.
Is there no other way to retrieve the images? Or do we have to set the library paths to be dynamic for our views?
Upvotes: 0
Views: 1205
Reputation: 15816
Old path:
/data/user/0/com.company.ourapp/files/Pictures/
It is obviously an Android file path instead of a iOS file Path. Android's file system is different from iOS.
Here is the new image path:
"/var/mobile/Containers/Data/Application/215E777E-A624-487E-B687-6647F8C0D1DC/Documents/01_18_2021_04_24_07_98524.jpg"
This is the right path to iOS document folder in sandbox. See this document about the Application directories in iOS.
I think you should distinguish iOS and Android when retrieving the images.
Which essentially makes it impossible for us to see pictures taken from a previous build/version of the app.
If the path really changes with different versions, you can get the app version number at runtime and give different filePath to different version.
(While I think your problem is the difference between iOS and Android file path.)
Upvotes: 0