objective-c - OS X下拖拉文件如何获取文件路径
迷茫
迷茫 2017-05-02 09:28:28
0
1
525

拖拉文件获取文件路径

// (id <NSDraggingInfo>)sender
NSURL *fileURL=[NSURL URLFromPasteboard: [sender draggingPasteboard]];

获取URL,打印2016-08-01 17:11:21.201 DragAndDrop[3504:170407] file:///.file/id=6571367.14796550。而不是如/Users/jolie/Downloads格式的文件路径。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
阿神
NSString *filePath = [fileURL path];

Reflection on the problem: This problem still took a lot of time. My initial idea was to get NSURL from Pasteboard. NSImage can also be initialized through Pasteboard, so I wanted to get fileName from Pasteboard. Since fileName is of string type, I wanted to get NSString. Initialized through Pasteboard, but not found. From the Apple API, we can see that NSString follows the NSPasteboardWriting and NSPasteboardReading protocols, but does not provide relevant interfaces.
However, a project pulled from github found that the answer to the problem is very simple. NSURL provides path to obtain the file path. The reason why the problem took so much time can only be said to be that I am not familiar with the NSURL API.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template