I'm writing a FinderSync extension that places an item in the context menu. When I right-click, I want the title of the menu item to change based on the selected file's contents. However, when I try to read the contents using Data(contentsOf: selectedUrl)
, it throws the following error:
Error Domain=NSCocoaErrorDomain Code=257 "The file “Some File.png” couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/Users/Shared/MySyncExtension Documents/Some File.png, NSUnderlyingError=0x61800004cf00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
This does not change if I add or remove sandboxing.
Prior Research
- The file couldn’t be opened because you don’t have permission to view it
- The compiler has always been set to the default
- Read and Write access for FinderSync extension in a sandboxed environment
- The entitlement is enabled. Also, this manifests with sandboxing turned off.
- "File could not open because you do not have permission to view it." | Official Apple Support Communities
- The file's permissions say "everyone" has "Read only" access