【发布时间】:2020-02-16 00:48:00
【问题描述】:
假设我在.intentdefinition 文件中定义了一个名为FooIntent 的自定义意图。
它有一个参数bar,类型为Decimal,对于它:
- User can supply value in Siri and Shortcuts app 处于活动状态。
- Default Value 是 0。
其自动生成的类定义现在如下所示:
public class FooIntent: INIntent {
@NSManaged public var bar: NSNumber?
}
如果我构造一个FooIntent,请将bar 设置为nil,并将其传递给INUIAddVoiceShortcutViewController:
let intent = FooIntent()
intent.bar = nil
intent.suggestedInvocationPhrase = "Do foo"
let shortcut = INShortcut(intent: intent)
let viewController = INUIAddVoiceShortcutViewController(shortcut: shortcut!)
viewController.delegate = self
window?.rootViewController?.present(viewController, animated: true, completion: nil)
Add to Siri 模态出现时,bar 参数用默认值 0 填充。
如果在Add to Siri UI 中,我将bar 更改为Ask Each Time 并按下Add to Siri,则生成的委托方法调用会生成一个INVoiceShortcut 对象,其中包含nil 的nil 值bar :
func addVoiceShortcutViewController(_ controller: INUIAddVoiceShortcutViewController, didFinishWith shortcut: INVoiceShortcut?, error: Error?) {
if let intent = shortcut?.shortcut.intent as? FooIntent {
print(intent.bar) // nil
}
controller.dismiss(animated: true, completion: nil)
}
如果我在 UI 中将 bar 设置为 Clipboard,也是如此。
如果我将它设置为一个值,例如42,然后intent.bar 正确返回42。
既然nil 似乎代表一个参数的多个概念,那么Ask Each Time 的概念存储在快捷方式或意图对象中的哪里?
有什么我可以传递给INUIAddVoiceShortcutViewController 的东西,比如intent.bar = <Ask Each Time>?
【问题讨论】:
标签: ios swift sirishortcuts