Siri意图建议的调用短语未显示在ShortcutViewController中

时间:2019-04-28 01:54:29

标签: swift siri sirikit sirishortcuts

我正在尝试为我的iOS应用程序启用一个简单的Siri Intent,并使用TableView单元格来调用INUIAddVoiceShortcutViewController,并以TableView作为其委托。但是,建议的调用词组应该显示在控制器视图中。

我是Swift的新手,所以我没有做太多尝试,因为我不知道该怎么做

调用功能是:

getSiriView() {
 intent.suggestedInvocationPhrase = "Get a joke"

 let siriView = INUIAddVoiceShortcutViewController(shortcut: INShortcut(intent: intent)!)

 siriView.delegate = self;
 self.present(siriView, animated: true, completion: nil)
}

及其委托扩展如下:

//
//  ViewControllerSiriExtensions.swift
//  Helium
//
//  Created by Richard Robinson on 2019-04-26.
//  Copyright © 2019 Richard Robinson. All rights reserved.
//

import Foundation
import IntentsUI

extension TableViewController: INUIAddVoiceShortcutButtonDelegate {
    func present(_ addVoiceShortcutViewController: INUIAddVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
        addVoiceShortcutViewController.delegate = self
        addVoiceShortcutViewController.modalPresentationStyle = .formSheet
        present(addVoiceShortcutViewController, animated: true, completion: nil)
    }

    func present(_ editVoiceShortcutViewController: INUIEditVoiceShortcutViewController, for addVoiceShortcutButton: INUIAddVoiceShortcutButton) {
        editVoiceShortcutViewController.delegate = self
        editVoiceShortcutViewController.modalPresentationStyle = .formSheet
        present(editVoiceShortcutViewController, animated: true, completion: nil)


    }

}

extension TableViewController: INUIAddVoiceShortcutViewControllerDelegate {
    public func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith voiceShortcut: INVoiceShortcut?, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }

    public func addVoiceShortcutViewControllerDidCancel(_ controller: INUIAddVoiceShortcutViewController) {
        controller.dismiss(animated: true, completion: nil)
    }
}

extension TableViewController: INUIEditVoiceShortcutViewControllerDelegate {
    public func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didUpdate voiceShortcut: INVoiceShortcut?, error: Error?) {
        controller.dismiss(animated: true, completion: nil)
    }

    public func editVoiceShortcutViewController(_ controller: INUIEditVoiceShortcutViewController, didDeleteVoiceShortcutWithIdentifier deletedVoiceShortcutIdentifier: UUID) {
        controller.dismiss(animated: true, completion: nil)
    }

    public func editVoiceShortcutViewControllerDidCancel(_ controller: INUIEditVoiceShortcutViewController) {
        controller.dismiss(animated: true, completion: nil)
    }
}

extension TableViewController {
    public var intent: JokeIntent {
        return JokeIntent()
    }
}

当前,控制器显示并正常工作,除了它不显示建议的短语。

0 个答案:

没有答案