Taylor
Taylor

Reputation: 6410

Disable "Share" submenu

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.

Upvotes: 2

Views: 147

Answers (1)

1024jp
1024jp

Reputation: 2208

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

class DocumentController: NSDocumentController {

    override var allowsAutomaticShareMenu: Bool {

        return false
    }
}

Upvotes: 4

Related Questions