3

我希望我的应用程序之前将文件的完整路径复制到剪贴板。

我试过这个:

NSPasteboard *p = [NSPasteboard generalPasteboard];
NSDictionary *options = [NSDictionary dictionary];
NSString *path = [[p readObjectsForClasses:[NSArray arrayWithObjects:[NSString class], nil] options:options] objectAtIndex:0];

这仅返回文件名,而不是路径。

你能帮助我吗?

4

1 回答 1

9

试试这个:

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *classes = [NSArray arrayWithObject:[NSURL class]];

NSDictionary *options = [NSDictionary dictionaryWithObject:
                         [NSNumber numberWithBool:YES] forKey:NSPasteboardURLReadingFileURLsOnlyKey];

NSArray *fileURLs =
[pasteboard readObjectsForClasses:classes options:options];

这直接来自 Apple 的粘贴板编程指南

于 2013-04-01T22:59:33.983 回答