You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Siri无法识别App Intents短语参数的问题排查

问题

我使用App Intents框架开发iOS应用,已创建OpenShowIntent支持两种外部打开节目的方式:

  • 调用快捷指令并提供节目名称;
  • 对Siri说出指令:Open [show name] in [app name]

通过快捷指令App手动调用时功能正常,但使用Siri语音指令时,Siri能识别应用名称,却无法捕获节目名称,执行后返回“Something went wrong”。需要解决该问题,让用户说出“Open {showname} in {appName}”时能在应用中打开对应节目。

原因分析
  1. 参数歧义:同时定义了ShowEntity类型的可选参数show和字符串类型的showName参数,Siri处理语音指令时无法正确映射节目名称到对应参数,且逻辑优先使用show参数,导致解析冲突。
  2. 参数绑定错误:参数摘要和快捷短语都绑定到了showName字符串参数,但Siri对实体类型参数的语音识别支持更完善,字符串参数无法有效提取语音中的节目名称。
解决方案
  1. 移除冗余的showName参数,仅保留ShowEntity类型参数作为唯一入口,让Siri通过实体查询自动处理节目名称的识别与匹配。
  2. 调整参数摘要和快捷短语,关联到show实体参数。
  3. 优化Intent执行逻辑,直接基于实体参数处理业务流程。
修改后的代码示例

OpenShowIntent.swift

import Foundation
import AppIntents
import Models

@available(iOS 16.0, *)
struct OpenShowIntent: AppIntent {
    static var title: LocalizedStringResource = "Open a Show"
    static var openAppWhenRun = true

    // 移除showName参数,将show设为可选(保留用户未指定时的选择逻辑)
    @Parameter(title: "Show", optionsProvider: ShowEntityQuery())
    var show: ShowEntity?

    static var parameterSummary: some ParameterSummary {
        // 关联到show实体参数
        Summary("Open \(\.$show) in (APP NAME)")
    }

    @MainActor
    func perform() async throws -> some IntentResult & ProvidesDialog {
        let showToOpen: ShowEntity
        
        if let show = show {
            showToOpen = show
        } else {
            // 若未提供实体,调用查询获取推荐节目让用户选择
            let suggestedEntities = try await ShowEntityQuery().suggestedEntities()
            showToOpen = try await $show.requestDisambiguation(
                among: suggestedEntities,
                dialog: "Choose a show from your bookmarks?"
            )
        }
        
        let deepLink = DeepLink(
            type: .show(
                showId: showToOpen.id,
                showDateStr: nil,
                voucher: nil,
                reviewModalParams: nil
            )
        )
        let url = try deepLink.createURL(source: nil)
        IntentsHelper.openLink(url: url)
        return .result(dialog: "Show '\(showToOpen.name)' opened successfully.")
    }
}

TTShortcuts.swift

import Foundation
import AppIntents

@available(iOS 16.0, *)
struct TTShortcuts: AppShortcutsProvider {
    static var appShortcuts: [AppShortcut] {
        return [
            AppShortcut(
                intent: OpenShowIntent(),
                phrases: [
                    "View show in \(.applicationName)",
                    "Open \(\.$show) in \(.applicationName)",
                    "Show \(\.$show) in \(.applicationName)",
                    "Find \(\.$show) in \(.applicationName)",
                    "Search for \(\.$show) in \(.applicationName)"
                ],
                shortTitle: "Open show",
                systemImageName: "pencil.circle"
            )
        ]
    }
    static var shortcutTileColor: ShortcutTileColor = .blue
}
额外说明
  • 移除showName后,Siri会自动将语音中的节目名称传递给ShowEntityQuery的entities(matching:)方法,获取匹配实体,无需手动处理字符串搜索。
  • 若需要支持模糊搜索,ShowEntityQuery已实现对应逻辑,Siri会返回匹配的节目列表,必要时请求用户确认。
  • 测试时确保设备Siri语言与应用本地化设置一致,避免识别偏差。

内容的提问来源于stack exchange,提问作者user26425844

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 20:55:12