gpt4 book ai didi

ios - SiriKit 自定义意图参数和快捷键

转载 作者:行者123 更新时间:2023-12-01 17:35:49 27 4
gpt4 key购买 nike

我正在尝试弄清楚如何使用 iOS12 中的自定义意图来定义和创建快捷方式。我想创建一个快捷方式,以便用户可以将任务添加到我的应用程序并为其命名(以及将来的其他参数)。例如只需对 Siri 说“添加名称为‘取洗衣物’的任务”。

这是我定义意图的方式: enter image description here

然后我尝试使用以下方法创建 Siri 快捷方式:

    TaskIntent *taskIntent = [[TaskIntent alloc] init];
taskIntent.suggestedInvocationPhrase = @"TaskIt";

INShortcut *taskShortcut = [[INShortcut alloc] initWithIntent:taskIntent];

INUIAddVoiceShortcutViewController *addSiri = [[INUIAddVoiceShortcutViewController alloc] initWithShortcut:taskShortcut];
addSiri.delegate = self;
[self presentViewController:addSiri animated:YES completion: nil];

但是,它最终在应用程序中出现异常:

Cannot create shortcut from intent ( { taskName = ; identifier = EE4661C6-1826-4A14-84EC-FD684647FE2B; }) because it has no valid parameter combinations

所以我不确定如何正确执行此操作。捐赠快捷方式时是否必须提供任务名称?但这意味着每次都会显示相同的 taskName 并将其添加到系统中,这不是我想要的。还是新的 SiriKit 的可定制性不足以处理通用输入?

最佳答案

是的,在创建了您的自定义 TaskIntent 之后,您需要填充其参数。也就是你需要为taskName设置一个值:

taskIntent.taskName = @"Test";

每次用户在您的应用中执行相关操作时,您都会捐赠意图。如果您的用户使用 taskName 输入任务,您可以通过创建您的意图并将 taskIntent.taskName 参数设置为用户输入的任务名称来捐赠此任务名称。它将建议再次输入具有相同标题的任务的快捷方式,这可能不是您想要的。添加任务不是重复的,因为任务标题不同,没有什么可以预测的,所以 INAddTasksIntent 似乎比捐赠快捷方式更合适。

关于ios - SiriKit 自定义意图参数和快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375013/

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