Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa: Drag and Drop any file type

I'm trying to create a drag and drop region that accepts any file type and will upload it to a server (using ASIHTTPRequest). I looked at the following example that Apple provides:

http://developer.apple.com/library/mac/#samplecode/CocoaDragAndDrop/Introduction/Intro.html

but it only covers dealing with the dragging and dropping of images. How can I set up my drag and drop operations to deal with any file type?

Thanks.

like image 909
minimalpop Avatar asked Dec 05 '10 00:12

minimalpop


1 Answers

Kind of related, but adding this in case it's helpful for someone:

If you simply want to handle any file dragged onto the application icon (doesn't need to be an Document-based app):

In .h:

- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames;

In .m:

- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames {
    NSLog(@"Files dragged on: %@", fileNames);
}

In your xxx.plist, create a new entry under CFBundleDocumentTypes:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>*</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>NSFilenamesPboardType</string>
        <key>CFBundleTypeRole</key>
        <string>None</string>
    </dict>
</array>
like image 66
glassfish Avatar answered Sep 27 '22 18:09

glassfish