我希望我的应用程序能够将文件的完整路径复制到剪贴板之前。
我试过了:
NSPasteboard *p = [NSPasteboard generalPasteboard];
NSDictionary *options = [NSDictionary dictionary];
NSString *path = [[p readObjectsForClasses:[NSArray arrayWithObjects:[NSString class], nil] options:options] objectAtIndex:0];
这只返回文件名,而不是路径。
你能帮助我吗?
答案 0 :(得分:8)
试试这个:
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的Pasteboard Programming Guide。