[英]FinderSync Extension runtime error: The file couldn’t be opened because you don’t have permission to view it
I'm writing a FinderSync extension that places an item in the context menu. 我正在编写一个FinderSync扩展,将项目放在上下文菜单中。 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: 但是,当我尝试使用Data(contentsOf: selectedUrl)
读取内容时,它会抛出以下错误:
Error Domain=NSCocoaErrorDomain Code=257 "The file “Some File.png” couldn't be opened because you don't have permission to view it." 错误域= NSCocoaErrorDomain代码= 257“无法打开文件”Some File.png“,因为您无权查看它。” UserInfo={NSFilePath=/Users/Shared/MySyncExtension Documents/Some File.png, NSUnderlyingError=0x61800004cf00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} UserInfo = {NSFilePath = / Users / Shared / MySyncExtension Documents / Some File.png,NSUnderlyingError = 0x61800004cf00 {Error Domain = NSPOSIXErrorDomain Code = 1“不允许操作”}}
This does not change if I add or remove sandboxing. 如果我添加或删除沙盒,这不会改变。
The issue is that the Sandbox is preventing file access to the file, and thus your app cannot open it. 问题是Sandbox阻止文件访问该文件,因此您的应用程序无法打开它。
Read and Write access for FinderSync extension in a sandboxed environment 沙盒环境中FinderSync扩展的读写访问权限
Even though the Finder Sync App Extension is granted "User Selected File" Sandbox File Access, the files accessed by the user via right-click seemingly do not count as being "user-selected". 即使Finder Sync App Extension被授予“用户选择文件”沙盒文件访问权限,用户通过右键单击访问的文件看起来也不算“用户选择”。
It may be possible to guide the user to select a root directory via an NSOpenPanel via Powerbox, after which all subdirectories can be accessed via a security-scoped bookmark . 可以引导用户通过Powerbox通过NSOpenPanel选择根目录,之后可以通过安全范围的书签访问所有子目录 。
Using a Temporary Exception entitlement is also a possibility, but will cause App Review problems: 使用临时例外权利也是可能的,但会导致App Review问题:
Is there any way to give my sandboxed Mac app read only access to files in ~/Library? 有没有办法让我的沙盒Mac应用程序只读访问〜/ Library中的文件?
Please duplicate my Apple bug report requesting this behavior be allowed: 请复制我的Apple错误报告,请求允许此行为:
Finder Sync App Extension
selectedItemURLs()
should receive "User Selected File" Sandbox file access. Finder Sync App ExtensionselectedItemURLs()
应该接收“用户选择的文件”Sandbox文件访问权限。rdar://42874694 rdar:// 42874694
https://openradar.appspot.com/radar?id=5063363058991104 https://openradar.appspot.com/radar?id=5063363058991104
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.