Repositioning documents after each debug test

In my application, I download images from the Internet and save them in the document directory. After forcibly closing the application and debugging it, the location of the document directory will again change. I believe that when assigning a new application identifier every time I debug the application ... is this normal behavior?

I store image file paths in CoreData, and then when I upload them, I print filePath to help me debug, and this is what I see:

/ var / mobile / Applications / 37A083EC-ED2E-4B40-80E3-E1E813AB3D1E / Documents / 2740-Chris Robinson Brotherhood.jpg

If I stop debugging on my real iPhone, I forcefully close the application and debug my file path stored in CoreData again, it remains the same as above, but when I refer to the document directory as a test, the application identifier changes:

/ VAR / mobile / Applications / D952D72B-E3AD-4085-99FD-7C06000DA66C / Documents

How can I get around this?

+6
source share
1 answer

Yes, this is normal and will happen on a real device launched by real users.

The solution is simple - just save the path relative to the Documents folder. You will get the path to the Documents folder at runtime, and then add the saved relative path to get the final path.

This allows your application to work even when the user updates the application to a new version, and the path to the application changes.

+8
source

Source: https://habr.com/ru/post/971883/


All Articles