在沙盒环境中对FinderSync扩展的读写访问权限 [英] Read and Write access for FinderSync extension in a sandboxed environment

查看:379
本文介绍了在沙盒环境中对FinderSync扩展的读写访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户右键单击Finder中的目录,然后找到自定义MenuItem.单击该项目将告诉我的应用打开一个窗口,用户可以在其中执行其工作.完成后,需要通过右键单击将文件写入所选的文件夹.

The user right-clicks a directory in Finder and finds a custom MenuItem. Clicking that Item will tell my app to open up a window where the user can do his work. When he is finished files need to be written to to the folder he selected by right-clicking.

我现在一切正常,但最后一部分.该扩展名无法写入所选的文件夹.

I got everything to work now, but the very last part. The extension can't write to the selected folder.

选择要与之交互的文件夹的用户似乎不是Powerbox的一部分-我个人理解它-仅通过openPanelsavePanel激活.如何获得与用户通过菜单项选择的文件夹进行交互的权限?我在开发人员库中找不到对该问题的任何可能解决方案的参考.不在沙盒指南中,不在扩展指南中.

The user selecting the folder he wants to interact with seems to not be part of the Powerbox which - how I understand it - is only activated with openPanel and savePanel. How do I get the rights to interact with the folder that the user selected through my menu item? I can't find a reference to any possible solution to that problem in the developer library. Not in the sandboxing guide not in the extensions guide.

如果无法使用选定的文件和文件夹,那么添加自定义菜单项的可能性将变得毫无用处,因此,我确定必须有一种访问它们的方法.

The possibility to add custom menu items would be rather useless if there was no way to use the selected files and folders so I'm sure there must be a way for accessing them.

也许我试图写的方式是错误的.我的主应用程序将一个临时文件写入共享组文件夹.之后,它会发送一条通知,通知该扩展程序侦听:

Maybe the way I'm trying to write is wrong. My main app writes a temporary file into a shared group folder. After that it sends a notification that the extension listens to:

func copyFile(notification:NSNotification)
{
    NSLog("write file")

    if let target = tmpTarget
    {
        let secureContainer = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.de.enie.Nu")
        let contents = NSFileManager.defaultManager().contentsOfDirectoryAtURL(secureContainer!, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions.SkipsHiddenFiles | NSDirectoryEnumerationOptions.SkipsPackageDescendants | NSDirectoryEnumerationOptions.SkipsSubdirectoryDescendants , error: nil)
        
        for content in contents as! [NSURL]
        {
            NSLog("tmp data: \(content.path!)")
            if content.lastPathComponent!.stringByDeletingPathExtension == "SharedData"
            {
                NSLog("found shared file")
                
                NSFileManager.defaultManager().copyItemAtURL(content, toURL: target.URLByAppendingPathComponent(content.lastPathComponent!), error: nil)
                
                NSFileManager.defaultManager().removeItemAtURL(content, error: nil)
            }
        }
        tmpTarget = nil
    }
}

尝试写入文件会导致以下控制台通知:

The attempt to write the file results in these console notifications:

  • 在/Users//Desktop/SharedData.png上打开:不允许操作
  • 拒绝文件写入创建/Users//Desktop/SharedData.png

任何有关如何访问用户选择的文件夹的想法都值得赞赏.

Any ideas how to get access to user selected folders are appreciated.

我只是向我保证我没有任何错误.虽然允许我通过NSOpenPanel访问文件夹(这意味着权利应该是正确的),但我无法在/中创建文件夹,甚至无法为默认FIFinderSyncController的目标网址添加书签.

I just reassured that I did no mistakes in any way. While I'm allowed to access folders via the NSOpenPanel (which means entitlements should be right) I can not create folders in / or even bookmark the target url of my default FIFinderSyncController.

推荐答案

即使Finder Sync App Extension被授予用户选择的文件"沙箱文件访问权限,用户仍可以通过Finder Sync App Extension访问selectedItemURLs()文件-click似乎不算是用户选择的".因此,沙盒会拒绝您的Finder Sync应用访问这些文件.

Even though the Finder Sync App Extension is granted "User Selected File" Sandbox File Access, the selectedItemURLs() files accessed by the user via Finder Sync App Extension right-click seemingly do not count as being "user-selected". The sandbox thus denies your Finder Sync app access to those files.

正如其他答案所指出的那样,解决此问题的唯一方法是使用临时授权来进行更广泛的文件访问.或使用Powerbox NSOpenPanel让用户选择一个包含文件夹,然后使用该安全作用域书签来访问沙盒文件.

As the other answer notes, the only way around this is to use a temporary entitlement for wider file access. Or to use a Powerbox NSOpenPanel to have the user select a containing folder, and use that security-scoped bookmark to access the sandboxed files.

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

Please duplicate my Apple bug report requesting this behavior be allowed:

Finder Sync应用程序扩展selectedItemURLs()应该会收到用户选择的文件"沙箱文件访问权限.

Finder Sync App Extension selectedItemURLs() should receive "User Selected File" Sandbox file access.

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

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

这篇关于在沙盒环境中对FinderSync扩展的读写访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆