在我的沙盒应用程序中,我试图将带有安全范围的NSURL放到粘贴板上,以便从NSTableView拖放到取景器(反之亦然)。
拖动的代码非常简单,基本上在带有NSURL数组的粘贴板上执行writeObjects:
- (BOOL) tableView:(NSTableView *)tv
writeRowsWithIndexes:(NSIndexSet *)rowIndexes
toPasteboard:(NSPasteboard *)pasteboard
{
Crate *selectedCrate = (Crate *)[self.cratesListController selectedObjects][0];
NSMutableArray *pasteboardArray = [NSMutableArray array];
[rowIndexes enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL *stop) {
Track *selectedTrack = [self.tracksViewedInTrackList objectAtIndex:rowIndex];
[selectedTrack addURLToPasteboardArray:pasteboardArray];
}];
if (!pasteboardArray.count) {
return NO;
}
for (NSURL *url in pasteboardArray) {
[url startAccessingSecurityScopedResource];
}
[pasteboard writeObjects:pasteboardArray];
for (NSURL *url in pasteboardArray) {
[url stopAccessingSecurityScopedResource];
}
return YES;
}
这很好用,我可以将文件放到我的桌面上,但是我记录了以下错误:
2013-11-19 10:29:30.897 Test[1287:532f] sandbox extension creation failed: permissions error for path: [/Users/didier/Music/Gigs/Air Miles (2000 And One & DJ Madskillz).aif]
2013-11-19 10:29:30.897 Test[1287:532f] __CFPasteboardCreateSandboxExtensionDataFromCFData : failed to obtain sandbox extension data for url [file:///Users/didier/Music/Gigs/Air%20Miles%20(2000%20And%20One%20&%20DJ%20Madskillz).aif?applesecurityscope=623934663665316437323138646462333764326637373538626564363731393563303065616233303b30303030303030303b30303030303030303b303030303030303030303030303032303b636f6d2e6170706c652e6170702d73616e64626f782e726561642d77726974653b30303030303030313b30313030303030343b303030303030303030303061336431343b2f75736572732f64616d69656e2f6d757369632f67696773]
尝试从粘贴板中检索网址时,在我自己的应用中删除,如下所示:
NSArray *urls = [pasteboard readObjectsForClasses:@[ [NSURL class] ]
options:@{
NSPasteboardURLReadingFileURLsOnlyKey : @YES }];
代码仍可正常工作,但会记录以下错误:
2013-11-19 10:37:57.220 Krates[1287:303] No valid sandbox extension for item: [789514] of flavor: [public.file-url] was created.
2013-11-19 10:37:57.220 Krates[1287:303] Failed to get a sandbox extensions for itemIdentifier (789514). The data for the sandbox extension was NULL
我是否忽略了这些或我在代码中遗漏了什么?