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

Siri Intent对话中自定义SwiftUI视图按钮无响应问题

Siri触发AppIntent对话框内按钮回调无效问题

我创建了一个AppIntent并添加到快捷指令中,使其可被Siri识别。说出触发短语后,Siri Intent对话框正常显示,我在对话框内添加了带有两个Intent按钮的自定义SwiftUI视图,但通过Siri触发时按钮的回调处理完全无效,而直接在快捷指令中触发则功能正常。我还尝试过不带Intent的UIButton跳转方案,但同样没有效果。(附图展示了Siri对话框内添加的自定义SwiftUI视图中的两个按钮)

相关代码

struct MyCustomIntent: AppIntent {
    static let title: LocalizedStringResource = "My Custom Intent"
    static var openAppWhenRun: Bool = false

    @MainActor
    func perform() async throws -> some ShowsSnippetView & ProvidesDialog {
        return .result(dialog: "Here are the details of your order", content: {
            OrderDetailsView()
        })
    }
}

struct OrderDetailsView: View {
    var body: some View {
        HStack {
            if #available(iOS 17.0, *) {
                Button(intent: ModifyOrderIntent(), label : { 
                    Text("Modify Order")
                })
                Button(intent: CancelOrderIntent(), label : {
                    Text("Cancel Order")
                })
            }
        }
    }
}

struct ModifyOrderIntent: AppIntent {
    static let title: LocalizedStringResource = "Modify Order"
    static var openAppWhenRun: Bool = true

    @MainActor
    func perform() async throws -> some OpensIntent {
        // 执行跳转至App内修改订单的页面
    }
}

struct CancelOrderIntent: AppIntent {
    static let title: LocalizedStringResource = "Cancel Order"
    static var openAppWhenRun: Bool = true

    @MainActor
    func perform() async throws -> some OpensIntent {
        // 执行跳转至App内取消订单的页面
    }
}

尝试的无Intent按钮代码

Button(action: {
     if let url = URL(string: "myap://open-order") {
          UIApplication.shared.open(url)
     }
}) {
    Text("Open Order")
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 04:48:19