首页 > 解决方案 > 使用完成块的自定义意图处理程序

问题描述

我正在使用自定义 Siri 意图来 ping 服务器。我用来 ping 的函数在完成块中返回,如下所示:

PingKit.trace(host: server.pingURL, maxTraceTTL: 15) { latency, _ in
    // Do something cool here
}

但是,当我尝试在我的自定义意图处理程序中使用它时,我从来没有得到我想要的反馈。是否有特定方法可以在意图处理程序中使用完成块函数,以便我可以成功执行以下操作?

func handle(intent: RunTestIntent, completion: @escaping (RunTestIntentResponse) -> Void) {
    let server = Server(name: "Google",
                        pingURL: "www.google.com",
                        isPingTestable: true,
                        ndtURL: "10.10.43.146:4443",
                        isNDTTestable: true,
                        geo: Geo.NorthAmerica)
   
    PingKit.trace(host: server.pingURL, maxTraceTTL: 15) { latency, _ in
        completion(RunTestIntentResponse.success(result: "Test Complete"))
    }
}

标签: swiftcompletionhandlersiri

解决方案


推荐阅读