繁体   English   中英

如何为使用 Mac Catalyst 移植到 Mac 的 iPad 应用程序设置“帮助”菜单选项?

[英]How do I setup the "Help" menu option for an iPad app being ported to the Mac using Mac Catalyst?

默认情况下,Mac Catalyst 会创建一个标题为“帮助”的菜单,该菜单应该包含应用程序的帮助。 但是,我没有找到有关如何实施帮助的文档。 对于标准 Mac 应用程序,您可以使用帮助手册。 但是,没有提及如何在 Mac Catalyst 中使用帮助手册。 我试图将 HelpBookDirectoryName 添加到 info.plist 但这不起作用。 有没有一种方法可以让帮助书与 Mac Catalyst 一起使用?

我们为我们的 iOS 应用程序使用基于 Web 的帮助系统,并将其添加到适当的 UIViewControllers 似乎可以连接我们 Catalyst 版本的帮助菜单命令:

    // Show some help.
@IBAction func showHelp(_ sender: Any) {
    UIApplication.shared.open(URL(string: "http://www.ourapp.com/faq")!)
}

// Return whether action can be performed.
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {

    if action == #selector(self.showHelp(_:)) {
        return true
    } else {
        return super.canPerformAction(action, withSender: sender)
    }
}

好的......我设法通过使用第三方应用程序(Help Crafter)来创建MyAppName.help文件/文件夹,但您可以手动完成。

创建MyAppName.help文件后,您需要将其复制到项目中的Resources文件夹。 我首先将文件复制到 Finder 中的 Resources 文件夹,然后将该文件拖到 Xcode 中的 Resources 文件夹中。

最重要的一步:将 Select 'Create Folder References' 拖入项目时。

我之前选择了“创建组”,但它从来没有奏效。

这个链接也有一些有用的信息,特别是如果您要手动创建 MyAppName.help 文件

http://swiftrien.blogspot.com/2015/06/adding-apple-help-to-os-x-application.html

简而言之, MyAppName.help文件/文件夹中将包含一个.plist文件,但您还需要在项目的.plist文件中添加两个键:

  • Help Book directory name -> .help文件的名称(从技术上讲,它是一个带有.help扩展名的目录)
  • Help Book identifier -> 对我来说是maccatalyst.com.nitramluap.MyAppName.help但它必须与密钥Bundle Identifier下的MyAppName.help .plist中的标识符相同

经过一番测试。 我发现以下方法最适合我。 对于 MacCatalyst 应用程序。

脚步:

将以下代码添加到 AppDelegate。 因此删除默认帮助。

override func buildMenu(with builder: UIMenuBuilder) {
    super.buildMenu(with: builder)
    builder.remove(menu: .help)
}

将以下选择器添加到 AppDelegate。 这将提供指向您的帮助网站的链接。

@IBAction func openHelp() {
    UIApplication.shared.open(URL(string: "https://www.legolas.me/blankbook-english")!)
}

最后,将以下代码添加到 buildMenu function。 在 builder.remove 之后。

let helpCommand = UIKeyCommand(input: "W", modifierFlags: [.command], action: #selector(openHelp))
helpCommand.title = "Blankbook's Guide"
let helpMenu = UIMenu(title: "Blankbook's Guide", image: nil, identifier: UIMenu.Identifier("guide"), options: .displayInline, children: [helpCommand])
builder.insertChild(helpMenu, atStartOfMenu: .application)

这是最终结果: 在此处输入图像描述

最简单的方法就是覆盖buildMenu(with:) function。 我在我的 App Delegate 中使用它:

override func buildMenu(with builder: UIMenuBuilder) {
    if let helpMenu = builder.menu(for: .help) {
        let helpKeyCommand = UIKeyCommand(input: "?", modifierFlags: [.command], action: #selector(helpAction))
        helpKeyCommand.title = NSLocalizedString("YOUR_APP_NAME Help", comment: "")
        let newHelpMenu = helpMenu.replacingChildren([helpKeyCommand])
        builder.replace(menu: .help, with: newHelpMenu)
    }
    
    super.buildMenu(with: builder)
}

@objc private func helpAction() {
    // Perform your action here
    print("help!")
}

我很感激自从上次讨论这个问题以来已经有几年了,但我希望它的答案之一可以让我添加一个帮助菜单链接到我最近移植到 macOS 的 iOS 应用程序的在线指南麦克催化剂。 我的应用程序使用 SwiftUI 生命周期,因此我必须手动添加 AppDelegate,这是我按照hackingwithswift.com的指导进行的。 Oscar的回复帮助了我,我可以在帮助菜单中插入一个链接; 但是,该链接始终被禁用。 最终我找到了一个解决方案,即丢弃Oscar的 helpAction() @objc function 并替换:

let helpKeyCommand = UIKeyCommand(input: "?", modifierFlags: [.command], action: #selector(helpAction))
helpKeyCommand.title = NSLocalizedString("YOUR_APP_NAME Help", comment: "")
let newHelpMenu = helpMenu.replacingChildren([helpKeyCommand])
builder.replace(menu: .help, with: newHelpMenu)

和:

let openHelpAction = UIAction(title: "YOUR_APP_NAME Help") { (action) in 
//Your code here
}
let newHelpMenu = helpMenu.replacingChildren([openHelpAction])
builder.replace(menu: .help, with: newHelpMenu)

我自己的 openHelpAction 中的操作代码很简单:

UIApplication.shared.open(URL(string: "https://www.crizzle.co.uk/inetworthHelp/index.html")!)

我现在在我的 iOS 应用程序的 Mac Catalyst 版本中具有可操作的帮助菜单功能,我将很快将新版本上传到 Mac App Store。 顺便说一句,我没有遇到任何问题,因为缺少帮助功能导致应用程序被 App Review 流程拒绝。 我曾经在我的应用程序中发送.help 文件,但 Big Sur 和 Monterey 之间的 .help UTType 有所更改,这使得 HelpViewer 中帮助文件的显示非常受欢迎,因此我开始发送我的应用程序,其中包含指向在线指南的链接确保帮助始终可用(只要用户在线); 这样做的一个附带好处是显着减小了我的应用程序包的大小。

另一个“顺便说一句”,可以帮助位于英国(Help Crafter 不可用)并希望生成类似 Apple 的在线帮助指南的用户,建议在此链接上尝试帮助文件生成功能: 米德尔马克 Middlemac 不如 Help Crafter 好用,需要在终端中大量使用 CLI; 但是,我相信结果非常好。

如果您想删除“应用程序帮助”菜单项,也许用自定义命令替换它以打开您的网站、联系支持、查看常见问题等,您可以用您自己的命令替换“帮助”菜单的子项,如下所示:

override func buildMenu(with builder: UIMenuBuilder) {
    super.buildMenu(with: builder)
        
    guard builder.system == .main else { return }

    builder.replaceChildren(ofMenu: .help) { menuElements in
        // We don't support App Help menu item as of now, so create our own custom menus
        return [
            UIMenu(options: .displayInline, children: [
                UICommand(title: "Frequently Asked Questions", action: #selector(faqsAction)),
                UICommand(title: "Contact Support", action: #selector(contactSupportAction))
            ]),
            UIMenu(options: .displayInline, children: [
                UICommand(title: "Privacy Policy", action: #selector(privacyPolicyAction)),
            ])
        ]
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM