【问题标题】:How do I setup the "Help" menu option for an iPad app being ported to the Mac using Mac Catalyst?如何为使用 Mac Catalyst 移植到 Mac 的 iPad 应用程序设置“帮助”菜单选项?
【发布时间】:2020-02-02 05:08:13
【问题描述】:

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

【问题讨论】:

    标签: ios macos mac-catalyst


    【解决方案1】:

    我们为我们的 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)
        }
    }
    

    【讨论】:

    • 还有其他方法吗? Apple 突然决定在我实施帮助菜单之前拒绝我的应用程序。
    • @sabiland 请参阅下面的回复。到目前为止,我在应用拒绝方面遇到了同样的问题。
    • 太棒了@PaulMartin 我会试试的。
    • 仅供参考,您可以将其放入 AppDelegate 类中,供那些使用 SwiftUI 的人使用。
    【解决方案2】:

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

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

    最重要的一步:将其拖入项目时选择“创建文件夹引用”。

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

    这个链接也有一些有用的信息,特别是如果您要手动创建 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 但它必须与 MyAppName.help .plist 下的 Bundle Identifier 键下的标识符相同

    【讨论】:

      【解决方案3】:

      经过一些测试。我发现以下方法最适合我。对于 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 函数中。在 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)
      

      这是最终结果:

      【讨论】:

      • App Store 允许这样做吗? OP 说他们的应用程序被拒绝,因为他们没有帮助菜单。您的示例也没有帮助菜单。
      • @leanne 我在我的应用程序中使用它。它已在 App Store 上架。所以我猜是的?
      【解决方案4】:

      最简单的方法就是重写buildMenu(with:) 函数。我在我的 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!")
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-06-18
        • 2014-05-04
        • 2012-05-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-20
        • 2012-09-27
        相关资源
        最近更新 更多