I'm currently using flutter to pass a String of a valid file path to Swift in order to gain access to a security scoped resource (this part might not be relevant)
So I have a function that accepts a String and goes like this:
public func requestAccessToFile(filePath: String) -> Bool {
let fileUrl = URL(fileURLWithPath: filePath)
return fileUrl.startAccessingSecurityScopedResource()
}
I know that startAccessingSecurityScopedResource not always returns true but in this case, it should, since if I try to access the file without this returning true I get permissions error.
A bit more context: If I try to call that startAccessingSecurityScopedResource as soon as I get the URL from the file picker, it does succeed, but if I do it with the function it fails (notice that the function is called with a String and I'm passing a path without the file:// protocol. eg. "/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Documents/afile.pdf"
So my guess is that the URL created by the file picker is somehow different that the one I'm creating with the string path. But not sure.
Thanks for your help in advance.