提供Siri Tip View中的示例参数。

huangapple go评论73阅读模式
英文:

Provide example parameter in a Siri Tip View

问题

我正在实现iOS 16应用程序快捷方式。我正在使用 SiriTipView 来向用户展示可能性。

我的 AddItem 意图具有一个参数,用于将 Item 添加到哪个 Box 实体中。快捷方式将提示用户输入此参数。

@available(iOS 16.0, *)
struct MyShortcuts: AppShortcutsProvider { 
    @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {  
        AppShortcut(intent: AddItem(), phrases: [
            "将新项目添加到 \(\.$box) 中的 \(.applicationName)",
            "在 \(.applicationName) 中添加新项目",
        ],
            shortTitle: "添加新项目",
            systemImageName: "pills"
        )
    }
}

我想要向 SiriTipView 添加一个示例的 Box(从用户的现有数据中获取,就像我在消除歧义时所做的那样)。

目前,提示视图未填充实体占位符:

"将新项目添加到 ${box} 中的 <My App Name>"

提示视图定义如下:

SiriTipView(intent: AddItem())

我意识到我可以只更改顶层短语,让它使用没有参数的短语,但我认为向用户展示他们可以提及盒子参数会更有用。

我尝试使用如下方式初始化提示视图的 IntentParameter

SiriTipView(intent: AddItem(box: IntentParameter<BoxAppEntity>()))

但我无法弄清楚如何为其提供一个示例的盒子实体。我想我需要知道如何使用具体实体初始化 IntentParameter

英文:

I am implementing iOS16 App Shortcuts. I am using SiriTipView to show users the possibilities.

My AddItem intent has a parameter for which Box entity to add the Item to. The shortcut will prompt for this.

@available(iOS 16.0, *)
struct MyShortcuts: AppShortcutsProvider { 
    @AppShortcutsBuilder static var appShortcuts: [AppShortcut] {  
        AppShortcut(intent: AddItem(), phrases: [
            &quot;Add new item to \(\.$box) in \(.applicationName)&quot;,
            &quot;Add new item in \(.applicationName)&quot;,
        ],
            shortTitle: &quot;Add New Item&quot;,
            systemImageName: &quot;pills&quot;
        )
    }
}

I would like to add an example Box (from the user's existing data, like I do for the disambiguation) to the SiriTipView.

Currently, the tip view does not fill in the entity placeholder:

&quot;Add new item to ${box} in &lt;My App Name&gt;&quot;

The tip view is defined like this.

SiriTipView(intent: AddItem())

I realise I could just change the topmost phrase and have it use the phrase without the parameter, but I think it would be useful to the user to see that they can speak the box parameter.

I tried initialising the tip view with an IntentParameter like this:

SiriTipView(intent: AddItem(box: IntentParameter&lt;BoxAppEntity&gt;))

But I could not figure out how to just give it an example box entity. I guess I need to know how to initialise an IntentParameter with a concrete entity.

答案1

得分: 4

M Y的答案指导我朝着正确的方向前进。

我发现,在许多IntentParameter的初始化器中,我的具体实体的名称被忽略了,或者在编译时出现了错误。

最后,我不得不这样设置wrappedValue

func getIntentParameter() -> IntentParameter<BoxAppEntity?> {
    let parameter = IntentParameter<BoxAppEntity?>(title: "Example Parameter")
    parameter.wrappedValue = BoxAppEntity(id: "boxID", displayString: "Box Name")
    return parameter
}

然后我在SiriTipView中使用了这个:

SiriTipView(intent: AddItem(box: getIntentParameter()))

getIntentParameter方法中,我可以根据一些任意用户数据简单地设置displayString

英文:

The answer by M Y led me in the right direction.

I found that with many of the IntentParameter initialisers, the name of my concrete entity was being ignored, or there were compile time errors.

In the end, I had to set the wrappedValue like this.

func getIntentParameter() -&gt; IntentParameter&lt;BoxAppEntity?&gt; {
    let parameter = IntentParameter&lt;BoxAppEntity?&gt;(title: &quot;Example Parameter&quot;)
    parameter.wrappedValue = BoxAppEntity(id: &quot;boxID&quot;, displayString: &quot;Box Name&quot;)
    return parameter
}

Then I used this in the SiriTipView:

SiriTipView(intent: AddItem(box: getIntentParameter()))

In the getIntentParameter method I can simply set the displayString based on some arbitrary user data.

huangapple
  • 本文由 发表于 2023年5月29日 16:41:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355844.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定