macOS app gets error when I attempt to open a file URL provided by SwiftUI fileImporter

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?

Answered by DTS Engineer in 805092022

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"

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"

macOS app gets error when I attempt to open a file URL provided by SwiftUI fileImporter
 
 
Q