我正在尝试创建一个接受任何文件类型的拖放区域,并将其上传到服务器(使用ASIHTTPRequest)。我查看了Apple提供的以下示例:
http://developer.apple.com/library/mac/#samplecode/CocoaDragAndDrop/Introduction/Intro.html
但它只涉及处理图像的拖放。如何设置拖放操作以处理任何文件类型?
感谢。
答案 0 :(得分:12)
有点相关,但如果它对某人有帮助,请添加它:
如果您只想处理拖动到应用程序图标上的任何文件(不需要是基于文档的应用程序):
在.h:
- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames;
在.m:
- (void)application:(NSApplication *)sender openFiles:(NSArray *) fileNames {
NSLog(@"Files dragged on: %@", fileNames);
}
在xxx.plist中,在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>
答案 1 :(得分:6)
根据此post判断,您可能只需要让您的视图注册NSFilenamesPboardType
而不是imagePastBoardTypes
来接收任意文件类型。