gpt4 book ai didi

ios - 设置后关闭 ShortcutViewController

转载 作者:搜寻专家 更新时间:2023-11-01 06:57:19 25 4
gpt4 key购买 nike

我在我的应用程序中使用 Intent 实现了 SiriShortcut。

我使用 Apple 在此处提供的代码设置了一个按钮“添加到 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)
}
}

但是一旦我在单击“确定”按钮时记录了一个短语, View 就不会消失。

我在控制台中得到的错误:

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)

最佳答案

希望对你有帮助

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

谢谢。

关于ios - 设置后关闭 ShortcutViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52775290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com