drag and drop onto program icon
configure the target
- in Xcode, Get Info on the desired target
- in the “Properties” tab, add a new document type
- give the item a name, such as: Tiff Image
- give the item a UTI, such as: public.tiff
- set the Store Type to Binary
- set the Role to Viewer
- this alone should make an image file dragged onto the program icon appear to work, but nothing will happen yet
establish an application delegate
In IB (Interface Builder) set a delegate for “File's Owner”, such as MyAppController
write the method to handle the drag and drop
Add this to the delegate of “File's Owner”
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename { NSFileManager *fm = [NSFileManager defaultManager]; if([fm isReadableFileAtPath:filename]){ [self openLocation:filename]; return YES; } return NO; }
write the method to handle the file
- (void)openLocation:(NSString *)newLocation {
if([fileManager fileExistsAtPath:newLocation]){ // do something }
}