diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift index 34e162387..5a050b840 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift @@ -1344,11 +1344,17 @@ class ChatApiStreamCallback: StreamCallback { os_log("收到函数调用: %{public}@", log: agentService.logger, type: .info, name) print("onFunctionCall=functionCall\(functionCall)") + if (name == "exit_interaction") { + agentService.stopRecognition() + } + try agentService.sendEvent(name: "function_call", data: [ "name": name, "arguments": functionCall ]) + + }catch{ print("liwei--------------- AI Call onFunctionCall 异常: \(error)") } @@ -1523,7 +1529,7 @@ class AudioPlayer { } func playStopSound() { -// playSound(named: "stop", fileType: "mp3") + playSound(named: "stop", fileType: "mp3") } func playCallingSound() { diff --git a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift index 76ca62770..6f2bcf72d 100644 --- a/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift +++ b/local_plugins/chat_api/ios/chat_api/Sources/chat_api/SystemFunctionHandler.swift @@ -568,7 +568,9 @@ private class TranslationModeHandler: FunctionHandler { } /// 发送短信处理器 -private class SendTextMessageHandler: FunctionHandler { +private class SendTextMessageHandler: NSObject, FunctionHandler, MFMessageComposeViewControllerDelegate { + private var continuation: CheckedContinuation? + func handle(arguments: [String: Any]) async throws -> String { guard let contact = arguments["contact"] as? String, let message = arguments["message"] as? String else { @@ -581,17 +583,19 @@ private class SendTextMessageHandler: FunctionHandler { private func sendTextMessage(contact: String, message: String) async -> Result { return await withCheckedContinuation { continuation in + self.continuation = continuation DispatchQueue.main.async { if MFMessageComposeViewController.canSendText() { let messageVC = MFMessageComposeViewController() messageVC.recipients = [contact] messageVC.body = message + messageVC.messageComposeDelegate = self // 设置 delegate if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let window = windowScene.windows.first, let rootViewController = window.rootViewController { rootViewController.present(messageVC, animated: true) - continuation.resume(returning: Result(success: true, message: "短信界面已打开")) + // 不在这里立即返回结果,等待用户操作 } else { continuation.resume(returning: Result(success: false, message: "无法打开短信界面")) } @@ -601,6 +605,33 @@ private class SendTextMessageHandler: FunctionHandler { } } } + + // MARK: - MFMessageComposeViewControllerDelegate + func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) { + controller.dismiss(animated: true) { + // 在界面关闭后返回结果 + let message: String + let success: Bool + + switch result { + case .cancelled: + message = "用户取消发送短信" + success = false + case .sent: + message = "短信发送成功" + success = true + case .failed: + message = "短信发送失败" + success = false + @unknown default: + message = "未知结果" + success = false + } + + self.continuation?.resume(returning: Result(success: success, message: message)) + self.continuation = nil + } + } } /// 拨打电话处理器