拖动文件遇到沙盒(__ CFPasteboardIssueSandboxExtensionForPath) [英] Drag Files come across Sandbox(__CFPasteboardIssueSandboxExtensionForPath)

查看:221
本文介绍了拖动文件遇到沙盒(__ CFPasteboardIssueSandboxExtensionForPath)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我处理拖动操作从浏览器视图到自定义视图。它在雪景中工作良好,但不是在具有沙箱的山狮。

 在浏览器视图中:
NSMutableArray * urls = [[[NSMutableArray alloc] init] autorelease];
..............把一些NSUrl到urls数组....................
[pasteboard writeObjects:[NSArray arrayWithArray:urls]];

在我的接收自定义视图:
NSArray * pasteboardItems = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSString class]] options:nil];
NSArray * pasteboardItems2 = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:nil];
NSArray * pasteboardItems3 = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSImage class]] options:nil];
NSLog(@%@,pasteboardItems);
NSLog(@%@,pasteboardItems2);
NSLog(@%@,pasteboardItems3);
我的日志是:
2012-08-09 18:33:43.886 iCollage [6885:303] __CFPasteboardIssueSandboxExtensionForPath:错误为[/ Users / xxxx / Library / Containers / xxxxxxxxxxxx / Data / Downloads / 1343902069。 jpg]
2012-08-09 18:33:44.546 iCollage [6885:303](file://localhost/Users/xxx/Library/Containers/xxxxxxxx/Data/Downloads/1343902069.jpg)
2012-08-09 18:33:44.547 iCollage [6885:303](file://localhost/Users/xxxxx/Library/Containers/xxxxxx/Data/Downloads/1343902069.jpg)
2012-08-09 18:33:44.547 iCollage [6885:303]()





1.如何解决这个错误__CFPasteboardIssueSandboxExtensionForPath;我参考的文档,没有发现任何东西。我是有权限访问该文件! ,可能是startAccessingSecurityScopedResource将帮助我,然后我尝试和失败



2.why pasteboardItems2有价值?我写到仅粘贴板的URL,但不是字符串。我可以从NSString类型和NSUrl类型获取url! (我尝试从iFinder拖动一个文件,url将只存在于pasteboardItems,但不是pasteboardItems2)。任何人知道为什么?我认为第一个问题会自动修复,当有人帮我解决这个问题。

解决方案

我相信 Apple 回答问题1:



重要:虽然你可以支持拖动文件路径,一般来说,
你应该避免这样做,除非你确定目标
应用程序永远不会在应用程序沙箱中运行。如果使用NSString,OS X
无法知道该字符串是否应该解释为
路径;因此,OS X不会将目标应用程序的沙箱扩展为
,允许访问该位置的文件或目录。


WRT到问题2,它看起来像是一个您已粘贴URL,因此读取 NSURL 对象似乎是正确的。但是我认为你应该使用下面的代码(也从上面的链接)实现拖动:

   - (BOOL)performDragOperation: (id< NSDraggingInfo>)sender 
{
NSPasteboard * pboard = [sender draggingPasteboard];

if([[pboard types] containsObject:NSFilenamesPboardType]){
NSArray * files = [pboard propertyListForType:NSFilenamesPboardType];
int numberOfFiles = [文件数];
//使用文件列表执行操作
}
return YES;
}


I processed drag operation from browser view to custom view.It work well in snow lepoard,but not in Mountain Lion with sandbox.

in browser view:
    NSMutableArray* urls = [[[NSMutableArray alloc] init] autorelease];
..............put some NSUrl to urls array....................
    [pasteboard writeObjects:[NSArray arrayWithArray:urls]];

in my receive custom view:
    NSArray* pasteboardItems = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSString class]] options:nil];
    NSArray* pasteboardItems2 = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:nil];
    NSArray* pasteboardItems3 = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSImage class]] options:nil];
    NSLog(@"%@",pasteboardItems);
    NSLog(@"%@",pasteboardItems2);
    NSLog(@"%@",pasteboardItems3);
my log is:
    2012-08-09 18:33:43.886 iCollage[6885:303] __CFPasteboardIssueSandboxExtensionForPath: error for [/Users/xxxx/Library/Containers/xxxxxxxxxxxx/Data/Downloads/1343902069.jpg]
    2012-08-09 18:33:44.546 iCollage[6885:303] ( "file://localhost/Users/xxx/Library/Containers/xxxxxxxx/Data/Downloads/1343902069.jpg")
    2012-08-09 18:33:44.547 iCollage[6885:303] ( "file://localhost/Users/xxxxx/Library/Containers/xxxxxx/Data/Downloads/1343902069.jpg")
    2012-08-09 18:33:44.547 iCollage[6885:303] ()

my question is:

1.how to fix this error __CFPasteboardIssueSandboxExtensionForPath;I refer the docs and found nothing about that.I am ensuer that i have the permission to access the file!google says, may be "startAccessingSecurityScopedResource" will help me, then i try and failed

2.why pasteboardItems2 have value?i write to pasteboard only url but not string.It disgusted me that I can get the url both from NSString type and NSUrl type! (I try drag a file from iFinder, the url will only exist in pasteboardItems but not pasteboardItems2).Anybody know why? I think the first problem will auto fixed when some one help me fix this problem.

解决方案

I believe Apple answer question 1:

Important: Although you can support dragging file paths, in general, you should avoid doing so unless you are certain that the destination app will never be run in an app sandbox. If you use an NSString, OS X has no way to know whether that string should be interpreted as a path; thus, OS X does not expand the destination app’s sandbox to allow access to the file or directory at that location. Instead, use an NSURL, a bookmark, or a filename pasteboard type.

WRT to question 2, it looks like you have pasted URLs so reading NSURL objects would seem to be correct. However I think you should implement the dragging using the following code (also from the link above):

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
    NSPasteboard *pboard = [sender draggingPasteboard];

    if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
        NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
        int numberOfFiles = [files count];
        // Perform operation using the list of files
    }
    return YES;
}

这篇关于拖动文件遇到沙盒(__ CFPasteboardIssueSandboxExtensionForPath)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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