- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我处理了从浏览器 View 到自定义 View 的拖动操作。它在雪豹中运行良好,但在带有沙箱的 Mountain Lion 中运行不佳。
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] ()
我的问题是:
1.如何修复此错误 __CFPasteboardIssueSandboxExtensionForPath;我引用了文档,但一无所获。我确信我有权访问该文件!谷歌说,可能是“startAccessingSecurityScopedResource”会帮助我,然后我试试失败了
2. 为什么 pasteboardItems2 有值(value)?我只写 url 而不是 string。令我恶心的是我可以从 NSString 类型和 NSUrl 类型中获取 url! (我尝试从 iFinder 中拖出一个文件,该 url 将只存在于 pasteboardItems 而不是 pasteboardItems2)。有人知道为什么吗?我认为当有人帮助我解决这个问题时,第一个问题会自动解决。
最佳答案
我相信Apple回答问题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.
关于问题 2,您似乎粘贴了 URL,因此读取 NSURL
对象似乎是正确的。但是我认为您应该使用以下代码(也来自上面的链接)实现拖动:
- (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;
}
关于objective-c - 拖动文件遇到沙箱(__CFPasteboardIssueSandboxExtensionForPath),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11881832/
我处理了从浏览器 View 到自定义 View 的拖动操作。它在雪豹中运行良好,但在带有沙箱的 Mountain Lion 中运行不佳。 in browser view: NSMutableA
我是一名优秀的程序员,十分优秀!