Hi there,
Introduction
I have been working on a Finder Sync extension and I would now like to use it to access a file the user has selected. This has been causing me significant issues (and I believe that a lot of other developers have also experienced similar issues with the extension).
Because I plan to release my app on the App Store, I need both the main app and the finder sync app to be sandboxed
Some example code describing the issue
When the user executes the custom finder action in the context menu, I use the following code to extract and access the selected files:
guard let target = FIFinderSyncController.default().selectedItemURLs() else {
NSLog("Failed to obtain targeted URLs: %@")
return
}
do {
//Read content of the first selected file (example)
let text = try String(contentsOf: target[0], encoding: .utf8)
}catch {
print("Some error occurred: \(error)")
}
The problem
Though these files should have a sandbox exception (because they are selected by the user), they do not and I get the following error because I seemingly do not have the permission (even though I should have):
Error Domain=NSCocoaErrorDomain Code=257 "The file “myfile.txt” couldn’t be opened because you don’t have permission to view it."
I know from my thorough research (refer to links) that a lot of other people working with Finder Sync extensions have had this problem in the past and that Apple has not provided an official way to fix this.
So essentially I am asking if Apple is planning to fix this bug in the near future or, if not, whether there is a workaround for this problem (while still passing the App Store review) and while keeping the main functionality of a context-menu like Finder Sync Extension.
Useful links
My previous question concerning the transfer of URLs given in the Finder Sync Extension
I already asked a similar question on how to share some file URLs between my Finder Sync Extension and the Main App, to which I received a presumably working answer, which would work if this problem didn't exist. The solution to passing this access between extension and main app is to create a security scoped bookmark. This is not possible as long as I can't even access the files in the context of the extension itself.
Here is the link to this aforementioned question I posted last month: Accessing a file in a sandboxed main app, which was selected in a Finder Sync Extension
Some people with the same issue (dating back as far as 2016
Someone on the Apple Developer Forum had a similar issue and the respondent suggested a multitude of hacky fixes: Swift file reading permission error on macOS sandbox
Here is someone on StackOverflow from someone who had the exact same issue. Multiple people mentioned there that this was a bug in the operating system and have filed multiple bug reports, which were all unanswered by Apple:
Read and Write access for FinderSync extension in a sandboxed environment