objective-c – 拖动文件遇到Sandbox(__ CFPasteboardIssueSandboxExtensionForPath)

objective-c – 拖动文件遇到Sandbox(__ CFPasteboardIssueSandboxExtensionForPath),第1张

概述我处理了从浏览器视图到自定义视图的拖动 *** 作.它在雪地上工作得很好,但在带有沙箱的Mountain Lion中却没有. in browser view: NSMutableArray* urls = [[[NSMutableArray alloc] init] autorelease];..............put some NSUrl to urls array.......... 我处理了从浏览器视图到自定义视图的拖动 *** 作.它在雪地上工作得很好,但在带有沙箱的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;我参考文档并没有发现任何关于那个.我有权访问该文件!Google说,可能是“startAccessingSecurityScopedResource”会帮助我,然后我尝试失败

2.为什么pasteboardItems2有价值?我只写了粘贴板而不是字符串.我很反感我可以从Nsstring类型和NSUrl类型获取url! (我尝试从iFinder拖动一个文件,网址只存在于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.

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 = [files count];        // Perform operation using the List of files    }    return YES;}
总结

以上是内存溢出为你收集整理的objective-c – 拖动文件遇到Sandbox(__ CFPasteboardIssueSandboxExtensionForPath)全部内容,希望文章能够帮你解决objective-c – 拖动文件遇到Sandbox(__ CFPasteboardIssueSandboxExtensionForPath)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1023112.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存