代码之家  ›  专栏  ›  技术社区  ›  Max0u

设置后关闭ShortcutViewController

  •  1
  • Max0u  · 技术社区  · 7 年前

    我在我的应用程序中故意实现SiriShortcut。

    我在这里设置了一个按钮“添加到Siri”,上面有苹果给出的代码: https://developer.apple.com/documentation/sirikit/inuiaddvoiceshortcutviewcontroller

     func addSiriButton(to view: UIView) {
        let button = INUIAddVoiceShortcutButton(style: .blackOutline)
        button.translatesAutoresizingMaskIntoConstraints = false
    
        view.addSubview(button)
        view.centerXAnchor.constraint(equalTo: button.centerXAnchor).isActive = true
        view.centerYAnchor.constraint(equalTo: button.centerYAnchor).isActive = true
    
        button.addTarget(self, action: #selector(addToSiri(_:)), for: .touchUpInside)
    }
    
    // Present the Add Shortcut view controller after the
    // user taps the "Add to Siri" button.
    @objc
    func addToSiri(_ sender: Any) {
        if let shortcut = INShortcut(intent: ProjectorOnIntent()) {
            let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut)
            viewController.modalPresentationStyle = .formSheet
            viewController.delegate = self as? INUIAddVoiceShortcutViewControllerDelegate // Object conforming to `INUIAddVoiceShortcutViewControllerDelegate`.
            present(viewController, animated: true, completion: nil)
        }
    }
    

    但一旦我记录了一个短语,当我点击“确定”按钮时,视图就不会消失。

    控制台中的错误:

    2018-10-12 10:16:51.985156+0200 AppName[1029:172350] [default] No results found for query: {(
    <_LSApplicationIsInstalledQuery: 0x28226e560>
    )}
    2018-10-12 10:16:51.989467+0200 AppName[1029:172263] [strings] ERROR: Add to Siri not found in 
    table Localizable of bundle CFBundle 0x111a01d00 </var/containers/Bundle/Application/DDADF244-FBCE-47C0-90F8-E8C8ADA6962E/AppName.app> (executable, loaded)
    
    1 回复  |  直到 7 年前
        1
  •  3
  •   V D Purohit Niki Trivedi    7 年前

    希望对你有帮助,

    class ViewController: UIViewController, INUIAddVoiceShortcutViewControllerDelegate, INUIEditVoiceShortcutViewControllerDelegate {
        func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) {
            controller.dismiss(animated: true, completion: nil)
        }
    
         func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier deletedVoiceShortcutIdentifier: UUID) {
            controller.dismiss(animated: true, completion: nil)
        }
    
        func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
             controller.dismiss(animated: true, completion: nil)
        }
    
        func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
             controller.dismiss(animated: true, completion: nil)
        }
    
        func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
            controller.dismiss(animated: true, completion: nil)
        }    
    }
    

    使用INUIAddVoiceShortcutViewControllerDelegate和INUIEditVoiceShortcutViewControllerDelegate

    非常感谢。