I have a follow up question on this topic. According to the documentation, startAccessingSecurityScopedResource() "returns true if the request to access the resource succeeded; otherwise, false"
This works fine for when called from .fileImporter. However when called from .dropDestination(for: URL.self) { urls, _ in ... then url.startAccessingSecurityScopedResource()will always return false. I'm importing the same files using these two methods.
if url.startAccessingSecurityScopedResource() == true {
let data = try Data(contentsOf: url) // works for .fileImporter
url.stopAccessingSecurityScopedResource()
} else {
throw EmbeddingsError.noAccess // but calls from .dropDestination(for: URL.self) { urls, _ in end up here
}
What does work is to ignore the return value of url.startAccessingSecurityScopedResource() like so:
_ = url.startAccessingSecurityScopedResource()
let data = try Data(contentsOf: url) // works for .fileImporter
url.stopAccessingSecurityScopedResource()
But that can't be the way it's supposed to work. Is there anything I'm missing?