Accepting drops of volumes on Dock icon
I'm writing a Cocoa application that nee开发者_开发问答ds to accept drops of mounted volumes on its Dock icon. It is not document-based; I intend to dispatch each volume to the appropriate handler in application:openFiles
.
I have gotten the Dock to light up my application's tile for the drag, but upon dropping, my application shows an alert: “The document [volume name] could not be opened. [My application] cannot open files of this type.” My application:openFiles:
method never runs, even though the delegate is hooked up and is sent other delegate messages.
So, what's the correct way to accept a drop of a volume onto my Dock tile?
Probably your Info.plist
is not properly set up. It should include something like this:
CFBundleDocumentTypes = (
{
LSItemContentTypes = (
"public.volume"
);
}
);
or you can use CFBundleOSTypes
and disk
instead if you need to support pre-10.5.
I was able to get application:openFiles:
to work by doing this.
If you're already doing that, it's probably Launch Services getting confused... clean and rebuild your project, try a different user account, use lsregister
, wave dead chickens, etc.
… the delegate is hooked up and is sent other delegate messages.
Or so I thought.
Mea culpa—I had, in fact, not even created the delegate. I'm not sure why I thought I had.
With the delegate instantiated and hooked up in the MainMenu nib, plus the Info.plist change Nicholas Riley suggested, the drops now work.
精彩评论