A sample to exemplify loading a bundle in iOS
Avid followers of my Twitter account know: I was looking for an easy, preferably human editable container for documents, and — being the old Mac developer I am — I went with bundles, stored in the Documents folder.
At some point in my app, the user can choose which file to use. And then, of course, on next launch, that file should be used. Selecting the file works all nice and well, including reading from the created Bundle
.
The problem occurs when the App is relaunched, and reads the absoluteString
of the file from the UserDefaults. This works, and I can create a URL from it. But creating a bundle fails, and I don't get any error. This happens on iOS 15 and 16, on device and in the simulator.
Is this some permissions things? Is the url not formatted correctly? What is going on?
- Launch the App, in the Simulator or on device
- Select "Copy Bundle" (You can "Test Resource Bundle", but it does not matter)
- Finally, select "Test Documents Bundle". You should see a picture
- Close the app, either by stopping it in Xcode or force quit
- Restart the App
You see the picture
You see the "Gear" placeholder