I'm using the SwiftUI .fileImporter()
modifier to present a file open panel to the user, and then I access the returned file URL using String(contentsOf:encoding:)
. Then I get an error, "The file “order_history.csv” couldn’t be opened because you don’t have permission to view it."
The thing is, my app (recently created in Xcode 16.1 beta from macOS template) has the User Selected File
entitlement set to "Read Only." It should allow reading such a file, should it not?
Is your app sandboxed?
If so, you’ll need to start and stop a security scope access around the code that reads the file. See Accessing files from the macOS App Sandbox.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"