2

Cocoa automatically adds a Share submenu in the File menu of my app:

Share menu

How can I disable this menu (or share commands globally) programmatically? I need to disable it when the user hasn't yet purchased the app via IAP.

It doesn't seem I can use validateUserInterfaceItem as I did with other commands like Save....

I understand via this question that the menu uses NSSharingService. However it's not clear from that question how to disable the menu that is automatically added.

I could hard-code the index and disable the menu item, but that's rather icky. Also, because the app is localized, using the item's title would be gross as well.

Taylor
  • 5,871
  • 2
  • 30
  • 64

1 Answers1

4

If you develop a document-based app, subclass NSDocumentController and override allowsAutomaticShareMenu to return false.

class DocumentController: NSDocumentController {

    override var allowsAutomaticShareMenu: Bool {

        return false
    }
}
1024jp
  • 2,058
  • 1
  • 16
  • 25
  • Thanks! How do I get it to use my custom DocumentController? – Taylor Oct 10 '18 at 17:11
  • 1
    Either programmatically invoke it in your NSApplicationDelegate's init() or put your DocumentController's instance in MainMenu.xib/Main.storyboard. See the very last part of https://developer.apple.com/library/archive/documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/KeyObjects/KeyObjects.html. – 1024jp Oct 11 '18 at 00:11