I am developing a flvplayer with cocoa. I want to drag a flv file from the finder and drop it to the webview window (I use it to view the flv). But I didn't have the path of this file from finder. This is my code:
_ (void)showflv(nsstring*)aa
{
..........
//Register to accept flv drag/drop
NSString *pboardType = NSCreateFileContentsPboardType(@"flv");
NSArray *dragTypes = [NSArray arrayWithObject:pboardType];
[self registerForDraggedTypes:dragTypes];
}
_ (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFileContentsPboardType] ) {
}
return YES;
}
I read the document about this.I find that the function of PerformDragOperation can be written like this:
_ (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSPasteboard *pboard = [sender draggingPasteboard];
if ( [[pboard types] containsObject:NSFileContentsPboardType] ) {
NSFileWrapper *fileContents = [pboard readFileWrapper];
// Perform operation using the file’s contents
}
return YES;
}
I can get the filecontents of this dragging file.but how to get the path?
NSString *fileName = [fileContents filename];
I did a test, it wasn't correct.