How to add Help menu to Maccatalyst App?

Hi,


Got my app rejected because the help menu (top barr) has no link.


How to add it from a Macacatlyst App?


Thanks

Replies

When you create an app, you have a help menu.

-> Do you see it in menuBar ?


This menu has an item 'MyApp Help' with a '?' shortcut

-> Do you see it ?


This item should be connected to a defaut system action showMenu

-> Is it the case ?


Otherwise, control-drag from the menu to the First responder (second orange cube icon atop of the menu bar in IB)

Select showHelp in the list.

I got the same rejection, and I was clueless because there's no menu bar in the storyboard, so I didn't know how to edit it.
It turns out you have to do it programmatically.

Read Optimizing your iPad App for Mac. It says:


The Mac version of your app comes with a standard menu bar. Customize it by adding and removing menu items using UIMenuBuilder.

There's a sample app in there, but here's are some snippets of the code I wrote.

In your AppDelegate class, override the buildMenu function if you want to remove unnecessary menus (my app is a game, so it doesn't need most of the default menus):

Code Block swift
    #if targetEnvironment(macCatalyst)
    override func buildMenu(with builder: UIMenuBuilder) {
        if builder.system == .main {
            builder.remove(menu: .edit)
            builder.remove(menu: .file)
            builder.remove(menu: .format)
        }
    }
    #endif


The help action, by default, calls a Selector in your App called showHelp. The way I found the name of the selector is by overriding canPerformAction in your main UIViewController and printing out the Selector:

Code Block swift
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
print(action)
return true
}


Anyway, you don't need that unless you are debugging. To override your help action, just add the showHelp selector to you main UIViewController. In this example, I open an external website (I haven't resubmitted my game yet, so I'm not sure opening a website is an accepted method for getting help):

Code Block swift
    @objc
    func showHelp(_ sender: Any?) {
        openLocalizedURL("helpURL")
    }


And as a bonus, here's my openLocalizedURL function:

Code Block swift
func openLocalizedURL(_ key: String) {
/* e.g. "http://mywebsite/spanish.html" */
    let localized = NSLocalizedString(key, comment: "link to localized URL")
    guard let url = URL(string: localized) else {
        NSLog("Bad URL: \(localized) (key: \(key))")
        return
    }
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, options: [:]) { success in
            if (!success) {
                NSLog("Failed to open URL: \(localized)")
            }
        }
    } else {
        UIApplication.shared.openURL(url)
    }
}


I hope that helps!


Claude31, the StoryBoard doesn't have a Menu Bar since it is an iOS app. Adding menu items dynamically through the main Delegate works but not for HELP. Any suggestions there would be appreciated.

I have created a HELP Bundle and it appears that needs to be inserted in a /Resources folder in the project. The problem appears to be with that folder. It seems it must a a special kind of folder? Then the main Plist needs to have two new references added.

When I do these tasks, I get a compile error. It references a signature issue but it doesn't make sense.

Some documentation from Apple would be great but, lets face it, Apple documentation is terrible at best and useless most of the time.

Thanks...