Siri快捷方式-在addVoiceShortcutViewController

时间:2020-09-01 21:05:29

标签: ios swift ios13 siri sirishortcuts

我有一个下面的代码的ViewController。现在,我看到了Add to Siri按钮,单击该按钮后,我会得到一个Add to Siri页面,该页面向我显示命令,操作和“添加到Siri”按钮。但是,单击该页面上的“添加到Siri”按钮后,该命令(例如“测试命令”)将无法识别,因为在下面的addVoiceShortcutViewController中,voiceShortcutnil应该包含“测试命令”。错误也为nil。此外,按下主屏幕按钮并打开Siri并说出“测试命令”,Siri会显示以下内容:“哦,有什么问题。请重试。”这是在iOS 13.6上。任何帮助将不胜感激,谢谢。

extension ViewController {
    @available(iOS 12.0, *)
    public var intent: TrackPackageIntent {
        let testIntent = TrackPackageIntent()
        testIntent.suggestedInvocationPhrase = "Test command"
        return testIntent
    }
}

extension ViewController: INUIAddVoiceShortcutButtonDelegate {
    @available(iOS 12.0, *)
    func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
        addVoiceShortcutViewController.delegate = self
        addVoiceShortcutViewController.modalPresentationStyle = .formSheet
        present(addVoiceShortcutViewController, animated: true, completion: nil)
    }
    
    @available(iOS 12.0, *)
    func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
        editVoiceShortcutViewController.delegate = self
        editVoiceShortcutViewController.modalPresentationStyle = .formSheet
        present(editVoiceShortcutViewController, animated: true, completion: nil)
    }
    
    
}

extension ViewController: INUIAddVoiceShortcutViewControllerDelegate {
    @available(iOS 12.0, *)
    func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }
    
    @available(iOS 12.0, *)
    func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
        controller.dismiss(animated: true, completion: nil)
    }
    
    
}

extension ViewController: INUIEditVoiceShortcutViewControllerDelegate {
    @available(iOS 12.0, *)
    func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }
    
    @available(iOS 12.0, *)
    func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier deletedVoiceShortcutIdentifier: UUID) {
        controller.dismiss(animated: true, completion: nil)
    }
    
    @available(iOS 12.0, *)
    func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
        controller.dismiss(animated: true, completion: nil)
    }
}

0 个答案:

没有答案