Cocoa: Drag and Drop any file type
Asked Answered
F

2

8

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.

Flodden answered 5/12, 2010 at 0:18 Comment(0)
D
6

Judging by this post, you'd probably just have to have your view register for NSFilenamesPboardType instead of the imagePastBoardTypes to receive arbitrary file types.

Deni answered 5/12, 2010 at 2:7 Comment(0)
B
12

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>
Bounder answered 27/9, 2011 at 16:29 Comment(0)
D
6

Judging by this post, you'd probably just have to have your view register for NSFilenamesPboardType instead of the imagePastBoardTypes to receive arbitrary file types.

Deni answered 5/12, 2010 at 2:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.