In my app I am downloading images from the internet and storing them in the documents directory. After forcing closed the app and debugging it again, the location of the documents directory seems to change. I believe its assigning a new app ID each time I debug the app... is this normal behavior?
I am storing the image file paths in CoreData and then when I load them I am printing the filePath to help me debug, and here is what I see:
/var/mobile/Applications/37A083EC-ED2E-4B40-80E3-E1E813AB3D1E/Documents/2740-Chris Robinson Brotherhood.jpg
If I stop debugging, and on my real iPhone I force the app closed, and debug again my file path stored in CoreData remains the same as above, but when I reference the documents directory as a test, it appears the app ID has changed:
/var/mobile/Applications/D952D72B-E3AD-4085-99FD-7C06000DA66C/Documents
How can I get around this?
Yes, this is normal and will happen on a real device run by real users.
The solution is simple - only store the path relative to the Documents folder. You get the path to the Documents folder at runtime and then append the stored relative path to get the final path.
This allows your app to work even when the user updates your app to a new version and the path to the app changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With