Hi forgive my English and also a newbie on flutter iOS, I have an app on flutter on iOS that users can take pictures and videos from their camera and gallery I'm using the image_picker package this has no problem, then I save it on the on its Application Documents Directory I tried following this guide
my code for getting the application directory is this
Directory _appDocDir;
_appDocDir = await getApplicationDocumentsDirectory();
final Directory _appMediaDir = Directory('${_appDocDir.path}/Pictures/');
return _appMediaDir;
added with a 'Pictures' directory this will give a path of
/Users/macman/Library/Developer/CoreSimulator/Devices/96060868-7E5C-4E15-9900-4D1D4B0B5ACE/data/Containers/Data/Application/BE7728A6-FF15-498E-91A0-A96A3DDE5B31/Documents/Pictures/D_IMG_0002.JPG
from the iOS-simulator I save it and put in the database, and after re-compiling the app or doing a build update the previewing the image/video path is not found anymore. I tried to save another image on this build it and gave this path
/Users/macman/Library/Developer/CoreSimulator/Devices/96060868-7E5C-4E15-9900-4D1D4B0B5ACE/data/Containers/Data/Application/9D634D91-07B8-43BE-8646-2A55833322DF/Documents/Pictures/D_IMG_0005.JPG
I noticed earlier path this part "/BE7728A6-FF15-498E-91A0-A96A3DDE5B31/" is changed every time I re-compile the app or make an update from the iOS device the image is not found. What is the most practice for this users able to save image am I doing it wrong?
Update: I tried changing my logic to change the saved path to only the base name (D_IMAGE_0005.JPG) then when previewing the image will call the current application documents directory but this does not work also.
Thank You
Hi don't save the whole path given by the getApplicationDocumentsDirectory() on you record, instead save only the basename, and every time you preview/load the image call the
getApplicationDocumentsDirectory() + 'Pictures/<basename>',
every time the app gets updated or recompiled on the iOS the appid changes, that is why your path fails to load on a recompile.
iOS removes the documents directory every time you reinstall the app if your application is running on a sandbox environment.
Please refer to this stackoverflow question for more clarification
Related
I am using Cordova fileSystem to download some mp3 Audio files thru my App. I am using cordova.file.cacheDirectory and creating a subfolder within that to store the downloaded files. However, the problem is that each time I make some changes and run the App on iPad I get a different path.
The usual pattern is
file:///var/mobile/Containers/Data/Application/13E9EA83-94A2-4950-811E-E491AC176A78/Library/Caches/MyFolder/MyFiles.mp3
However the long number (App UUID) is not consistent. It changes each time I run the App on iPad through Xcode. Because of this I am unable to access, play, delete any files downloaded during the previous session because I am saving the file names with absolute path in a separate file for quick access in the future.
After some R&D I have realized that even though UUID changes each time, it actually refers to the same location. Hence the solution is not to save absolute path and instead, save only the Path beyond "/MyFolder/" in the above example. Each time when the App is run, the Base Path, which is actually file.cordova.cacheDirectory, should be appended to each entry to obtain the absolute Path to the file.
I need to download files, and store then in the dataDirectory. But When i start an application then i print:
console.log(cordova.file.dataDirectory);
file:///var/mobile/Containers/Data/Application/C5990CAA-439A-446E-A0B2-1212D3DC1072/Library/NoCloud/
When i build the application again, and prints the same console.log i got
file:///var/mobile/Containers/Data/Application/40C1C96E-E4EF-4F20-82C0-D13AA0385202/Library/NoCloud/
cordova.file.dataDirectory - Are a Persistent and private data storage within the application's sandbox using internal memory.
On each build on iOS the dataDirectory will be changed, but the files is "moved to new" folder. I dont found any documentation with tecnichal info.
To resolve you need save only de path after dataDirectory, for example
Your file will be safe in
file:///var/mobile/Containers/Data/Application/40C1C96E-E4EF-4F20-82C0-D13AA0385202/Library/NoCloud/user/files/image.png
You need save only user/files/image.png
To execute any operation with the file, copy, move, show you will use the cordova.file.dataDirectory + user/files/image.png
If someone has the same problem using Capacitor, I had to do this to be able to see my pictures again after an update
photo.webviewPath = Capacitor.convertFileSrc(this.file.dataDirectory + photo.fileName).replace('Library/NoCloud', 'Documents');
I've come across a problem I can't find a solution to. I've searched the forums extensively but can't find anything. Hopefully someone might be able to shed some light.
I have an app that can save images. They are saved to the apps documents directory and the path to them is saved in a sqlite database. Every time I run/build the app, it can no longer retrieve the images that are already in the documents directory. During that same build phase I can re-save the images and then I can retrieve them just fine, but as soon as I run/build the app again it can't retrieve the images. The images are not being deleted and the path is still correct.
This is how I try retrieving them in my ViewDidLoad method
//database was opened. Getting path to image
NSString *logoPath = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 21)];
//use path to load image to a UIImage view
[self.logoView setImage:[UIImage imageWithContentsOfFile:logoPath]];
I have confirmed that the image is in the documents directory still and the path is correctly assigned in my first line of code above. This code only fails when I run/build the app. Once the app is running I can save images to the directory and retrieve them with this same code just fine, but once I run/build the app again, the images I saved on the previous build can't be pulled up even though I can see them in the directory still (I use iExplorer to view my iPhones directories).
Any ideas? Im thinking that maybe I have to initiate those images in the directory somehow in order to use them right after I build.
UPDATE - Some more info in case it will help. After the app is built on my iPhone, I can close the app and reopen it and the images work just fine. I can even completely close the app (double click home button and end app process) and when I relaunch the app the images are retrieved from the directory just fine. But as soon as I build the app again through xCode, I cannot access the images. Something is changing when a new build is done.
UPDATE 2 - I think I found the issue and it is in the path.
This is my path
/var/mobile/Containers/Data/Application/8A387845-7B1F-4228-9E7E-2498EC302C5A/Documents/RYal7UXrLvcompanyLogo.png
After I build the app again, this is now the new path when I save the image again
/var/mobile/Containers/Data/Application/C0C30E2F-05D8-48F4-A0FF-603359AF5130/Documents/RYal7UXrLvcompanyLogo.png
Looks like the part in between Applications and Documents changes after every build so the path I am saving in my sqlite db is no longer valid after a new build. So now I need to figure out what that middle part is that keeps changing and how to get it after each build so I can update my paths to my images.
The issue was the path. Every time a new build was created, part of the path to the documents directory changed. See UPDATE 2 in the original question above.
is there a way that I can add sample files to the documents folder of an iOS-app before the app is actually started for the first time. For instance at install time.
For instance, I am writing a text editor and want to have a sample document, that the user can look at showing some of the features of the app. Could this sample be placed in some folder in Xcode and added to the documents folder automatically or do I have to add it from my code, the first time the app starts?
You can access files in sandbox.
Add some resources files. You can load them and save them the way you want.
Oddest issue, thought I would see if anyone had run into this before.
We have an iPad application that stores PDF files in the documents directory. All goes great, we can open the PDF's with CGPDFDocumentCreateWithURL all day long. Then, we reinstall the application from the same adhoc site, and for some reason are not able to load the files. We can iterate the documents folder, see the files there, but can't open them. We just get a nil back from CGPDFDocumentCreateWithURL.
This feels very much like the permissions on the files change after the update, but can't prove that.
So, has anyone encountered this post update? Is there anyway to get a error return from CGPDFDocumentCreateWithURL?
We encountered a similar problem recently and perhaps the same is happening to you.
Are you using the complete URL/path which you had (probably) saved before you updated the application.
The reason is that the App_Home directory changes on updates. So if earlier it was:
/var/mobile/applications/<guid1>/
after the update it will become
/var/mobile/applications/<guid2>/
The solution is to save relative paths from App_Home directory.