There’s a mistake I make every 6 months or so and I hope writing a blog post about it will finally engrave it into the back of my mind.
Have you seen how the file paths look like for the files in your iOS app’s little sandbox? Something like this:
The mistake I make is that I take this full URL and then save it into to Core Data storage or wherever (in this case, as order file path). And this will work if you never make updates to the app. However, if you do publish an update to the app, this URL will not be valid anymore.
The gibberish bit in the middle -
F71BA910-A1F0-4B39-85CB-775806ACFF62 - is path that is specific to a given app version. So, when you update, your new app version will get some other string in there and all your previously saved / hard-coded URLs will be useless.
What you need to save is only the part that you control and maintain - in my case that’s
orders/1832006/1.pdf. Which excludes the
Documents part as well as this is automatically created by iOS for your app.
Documents is one of several app directories that you can and should fetch using the provided iOS APIs. There is nothing that guaranties that in some future iOS versions Apple won’t rename Documents to something else, so you should not think it’s there to stay.
So, what’s the proper way to read/save local path files?