iOS is removing image files from device


#1

Hi guys,

My app downloads images and video files from an API onto the app I’m developing for offline use. I use the FileTransfer plugin then save images/videos to the dataDirectory and files do successfully get saved. I have data stored in SQLlite which stores the file locations where these images/videos have been saved to on the device. Upon save (if iOS), I remove the “file://” prefix when saving the location and have also used Ionic’s normalizeURL function. At this stage all files work perfectly.

When revisiting the app after multiple times (the amount of times can vary - usually 3-4), some images and videos that were once loading fine now return 404s. The files that do return 404s change each time I test. Please note that it is the same set of files that are always downloaded. There is no correlation.

This works fine on Android - just not iOS.

I have also added “Library” as the persistent file location as recommended by the File plugin, using the following:

<preference name="iosPersistentFileLocation" value="Library" />

If anyone has any advice on how to make these files persist in storage or reasoning behind why these files suddenly start returning 404s please advise.

Thanks in advance.

UPDATE: Since iOS changes the directory name that the files are in on each update, I am only storing the filename in SQLlite. On load of the app, I prepend the file.dataDirectory to each filename to get the actual path. I’ve checked (I may be wrong) but in production, the directory name will change with each update.


#2

It appears that each time the app is deployed (hopefully just whilst developing) the data directory changes for the app.

For example, on initial load the location was:
http://localhost:8080/var/mobile/Containers/Data/Application/10EC7806-7658-4F1C-8747-1AEAC61E8B6F/Library/NoCloud/filename.jpg

The next time the app was deployed, the directory/GUID changed to:
http://localhost:8080/var/mobile/Containers/Data/Application/2E1ECE70-8713-49B0-B088-90C647055961/Library/NoCloud/filename.jpg

So the files are still there, but under a different GUID. I’m just not sure whether the GUID remains consistent if the app is in production. If not, the only solution is to save the filename after the data directory and on load add the data directory path before the file.

If anyone has any experience on this matter, please advise. Thanks.