I've written a little utility targeting Mac, for personal use. In it, I need to be able to select a file from an arbitrary location on my drive.
I have the "user selected file" entitlement added, and I have added my application to "Full Disk Access." But I still get a permissions error when I select a file with the file-open dialog (via .fileImporter).
I dragged the application from the Xcode build directory to Applications before adding it to Full Disk Access. Any ideas?
Thanks! That does work, with the slight addition of having to call that method on the URL returned by the file dialog. So my button to open a file in SwiftUI looks like:
Button(action: { isImporting = true }, label: { Text("Open P8 file") })
.fileImporter(isPresented: $isImporting,
allowedContentTypes: [.data],
onCompletion: { result in
switch result
{
case .success(let theURL):
do
{
let didStart = theURL.startAccessingSecurityScopedResource()
defer
{
if didStart
{
theURL.stopAccessingSecurityScopedResource()
}
}
secretKey = try String(contentsOf: theURL, encoding: .utf8)
generateToken()
}
catch
{
message = error.localizedDescription
}
case .failure(let error):
print(error)
}
})
I filed a bug report on the documentation.