tags:

views:

241

answers:

3

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.

+4  A: 

Like so:

NSArray *draggedFilePaths = [pboard propertyListForType:NSFilenamesPboardType];
Chuck
A: 

I did a test ,but The draggedFilePaths didn't work.I found that the code: NSPasteboard *pboard = [sender draggingPasteboard];

if ( [[pboard types] containsObject:NSFileContentsPboardType] ) {
    //NSFileWrapper *fileContents = [pboard readFileWrapper];
    // Perform operation using the file’s contents

nslog(@"aa"); } when the app run ,the string "aa" didn't appear,why?

jin
A: 

Somebody who knows it maybe tell me why,Thanks!

jin