使用空参数调用 IntentHandler

IntentHandler called with empty parameter

我是 iOS 开发的新手,我正在尝试为我的应用程序添加对 Siri 快捷方式的支持,目的是让 Siri 在各种“Siri 建议”中建议常见的用户操作iOS 14.

中的小部件

使用 Apple 的文档和其他各种资源,我设法达到了创建意图、传递参数并将意图捐赠给 OS 的地步(以 INInteraction 的形式).到目前为止,它们还没有出现在小部件中,但我可以在 Siri 搜索中看到建议。

但是,当点击快捷方式时,我的 IntentHandler 被调用时的意图基本上是空的。当我在接收时打印意图时,它是正确的class,但它的参数是空的。

我的意图定义

用作意图参数的 StatusUpdate 类型

意向捐赠码

func donateInteraction(for status: StoredStatus) {
    //  Create the intent we're going to donate
    let intent = SetStatusIntent()
    // Create the status `type` associated with the intent, and add it to the intent
    let statusUpdate = StatusUpdate(identifier: status.uuid, display: status.status.asString)
    intent.status = statusUpdate
    
    let interaction = INInteraction(intent: intent, response: nil)
    // The identifier is used to match with the donation so the interaction
    // can be deleted if the status is removed.
    interaction.identifier = status.uuid
    
    interaction.donate { (error) in
        if error != nil {
            print(error as Any)
        }
    }
}

基本上,我希望快捷方式到达 IntentHandler 时带有用户执行的操作的某种形式的标识符。我想这就是参数的用途,但它似乎并没有真正传递这个参数,即使 suggestion in the search results 特定于我创建的交互。

我很想知道我在这里做错了什么,而且 — 此外 — 如果有原因建议只显示在搜索屏幕上,而不是任何建议小部件中。

感谢朋友的帮助,我发现取消选中“Intent is user configurable in the Shortcuts app…”选项似乎可以解决这个问题。

不知道为什么,这可能是 Apple 方面的一个错误。但它有效!