问题
I am Developing the zip extractor app in cocoa for which i'm using findersync to show context menu item. But, the problem is item is showing for every file i want to show only for .zip files so how do i do that .
Any Suggestion.
Thanks in Advance!
回答1:
Try this
NSURL *selectedURL = FIFinderSyncController.defaultController.selectedItemURLs[0];
NSURL *fileURL = selectedURL.filePathURL;
if([fileURL.pathExtension isEqualToString:@"zip"]) {
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
NSMenuItem *item = [menu addItemWithTitle:@"Hello" action:@selector(itemTarget:) keyEquivalent:@""];
item.target = self;
return menu;
}
回答2:
Consider adding a service instead. That will allow you to add your item for any file not just those in monitored folders. The plist entries for a service allow you to directly specify what file types are acceptable, i.e. Restrict the service to ZIP files
来源:https://stackoverflow.com/questions/51628512/how-to-give-context-menu-item-for-zip-files-only