Hello @eskimo,
I am experiencing exactly the same issue.
I use UIDocumentPickerViewController to select files;
receive urls in didPickDocumentsAt:;
fopen these files to read;
I select a file from Downloads;
When I build it with Debug configuration and run it on my device – I can read the contents of these files.
When I build it with Release configuration and run it on the same device – I get permission errors.
In Debug configuration startAccessingSecurityScopedResource has effect – I can't access the file without it.
Does not matter if I'm attached with a debugger or not, it's the build configuration that matters.
UPDATE:
... so I diffed xcodebuild -showBuildSettings -configuration {Release,Debug}, and turned out it was SWIFT_OPTIMIZATION_LEVEL. With -Onone (Debug) I could read the files, but with -O (Release) I could not.
The issue with my code turned out to be trivial :)
My code:
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
urls.forEach { assert($0.startAccessingSecurityScopedResource() }
// ...
I guess my assert(...) expression got stripped because of the optimization.
// that worked:
_ = $0.startAccessingSecurityScopedResource()
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: