【问题标题】:FinderSync Extension runtime error: The file couldn’t be opened because you don’t have permission to view itFinderSync 扩展运行时错误:无法打开该文件,因为您无权查看它
【发布时间】:2017-06-07 15:50:11
【问题描述】:

我正在编写一个 FinderSync 扩展,它将一个项目放在上下文菜单中。当我右键单击时,我希望菜单项的标题根据所选文件的内容进行更改。但是,当我尝试使用Data(contentsOf: selectedUrl) 读取内容时,会引发以下错误:

Error Domain=NSCocoaErrorDomain Code=257 "无法打开文件“Some File.png”,因为您没有查看权限。" UserInfo={NSFilePath=/Users/Shared/MySyncExtension Documents/Some File.png, NSUnderlyingError=0x61800004cf00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not allowed"}}

如果我添加或删除沙盒,这不会改变。


先前的研究

【问题讨论】:

    标签: swift cocoa sandbox nsfilemanager findersync


    【解决方案1】:

    问题是沙盒阻止文件访问文件,因此您的应用无法打开它。

    Read and Write access for FinderSync extension in a sandboxed environment

    即使 Finder Sync 应用程序扩展被授予“用户选择的文件”沙盒文件访问权限,用户通过右键单击访问的文件似乎不算是“用户选择的”。

    或许可以引导用户到select a root directory via an NSOpenPanel via Powerbox, after which all subdirectories can be accessed via a security-scoped bookmark

    使用临时例外权利也是可能的,但会导致 App Review 问题:

    Is there any way to give my sandboxed Mac app read only access to files in ~/Library?

    请复制我的 Apple 错误报告,要求允许此行为:

    Finder Sync 应用程序扩展 selectedItemURLs() 应该接收“用户选择的文件”沙盒文件访问权限。

    rdar://42874694
    https://openradar.appspot.com/radar?id=5063363058991104

    【讨论】:

      猜你喜欢
      • 2020-03-12
      • 2014-07-09
      • 1970-01-01
      • 2018-08-09
      • 2020-06-09
      • 2016-03-10
      • 1970-01-01
      • 2015-02-23
      相关资源
      最近更新 更多