Cocoa: drag any type of file

I am trying to create a drag and drop scope that accepts any type of file and will upload it to the server (using ASIHTTPRequest). I reviewed the following example that Apple provides:

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

but it only covers dragging and dropping images. How can I configure my drag and drop operations to work with any type of file?

Thanks.

+7
objective-c file-type cocoa drag-and-drop
source share
2 answers

Judging by the message, you probably just need to register your register for NSFilenamesPboardType instead of imagePastBoardTypes to get arbitrary file types.

+5
source share

Kind of related, but adding this in case it is useful to someone:

If you just want to process any file dragged onto the application icon (it’s not necessary to be a document-based application):

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 in 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> 
+11
source share

All Articles