How to give context menu item for .zip files only?

只谈情不闲聊 提交于 2019-12-11 06:53:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!