2011-08-10 18 views
0

如何从Cocoa应用程序的iTunes中拖动行?将行拖出iTunes进入可可应用程序

我在我的应用程序中有两个接受拖放的对象:一个NSTableView和一个自定义视图。两者都能识别从查找器拖出的文件,但都不识别从iTunes拖出的行。

+0

你想从iTunes行中得到什么?媒体,标题,... – spudwaffle

+0

filepath。我有答案,但由于我的声誉得分很低,我无法再发布5个小时。 – Colin

回答

1

嗯,这是答案。这将处理从iTunes中拖动东西,以及从查找器中拖动文件。你得到的是一个文件路径列表。 “发件人”是拥有拖纸板的人。简短的回答是,“com.apple.pasteboard.promised-file-url”是iTunes paste所需的关键。

NSMutableArray *paths = [NSMutableArray arrayWithCapacity:1]; 
NSArray *pasteboardTypes = [NSArray arrayWithObjects:@"com.apple.pasteboard.promised-file-url", @"public.file-url", nil]; 
for(NSPasteboardItem *item in [[sender draggingPasteboard] pasteboardItems]) { 
    NSString *urlString = nil; 
    for(NSString *type in pasteboardTypes) { 
    if([[item types] containsObject:type]) { 
     urlString = [item stringForType:type]; 
     break; 
    } 
    } 
    if(urlString) { 
    NSString *path = [[NSURL URLWithString:urlString] path]; 
    [paths addObject:path]; 
    } 
} 
NSLog(@"Pasted Paths: %@", paths); 
相关问题