diff --git a/CHANGELOG.md b/CHANGELOG.md index e8d77908..8800c090 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## 0.3.1 +* Fix: [iOS] Fix `hangUp()` not ending incoming call when call is ringing. [Issue #244](https://github.com/cybex-dev/twilio_voice/issues/244) +* Feat: [iOS] Add missing `answer()` native implementation. [Issue #244](https://github.com/cybex-dev/twilio_voice/issues/244) * Feat: Add raw `Connect({Map?})` for all platforms * Refactor: [Web] Removed unused `web_callkit` event listeners. * Fix: [Web] Check if call SID is present when call is disconnected (this occurs if the call ends abruptly after starting, and `params` does not contain `CallSid`). diff --git a/ios/Classes/SwiftTwilioVoicePlugin.swift b/ios/Classes/SwiftTwilioVoicePlugin.swift index 20741c60..91647558 100644 --- a/ios/Classes/SwiftTwilioVoicePlugin.swift +++ b/ios/Classes/SwiftTwilioVoicePlugin.swift @@ -268,7 +268,14 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand eventSink(!isOnHold ? "Hold" : "Unhold") } else if flutterCall.method == "answer" { - // nuthin + if(self.callInvite != nil) { + let ci = self.callInvite! + self.sendPhoneCallEvents(description: "LOG|answer method invoked", isError: false) + self.answerCall(callInvite: ci) + } else { + let ferror: FlutterError = FlutterError(code: "ANSWER_ERROR", message: "No call invite to answer", details: nil) + _result!(ferror) + } } else if flutterCall.method == "unregister" { guard let deviceToken = deviceToken else { @@ -287,6 +294,8 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand self.userInitiatedDisconnect = true performEndCallAction(uuid: self.call!.uuid!) //self.toggleUIState(isEnabled: false, showCallControl: false) + } else if(self.callInvite != nil) { + performEndCallAction(uuid: self.callInvite!.uuid) } }else if flutterCall.method == "registerClient"{ guard let clientId = arguments["id"] as? String, let clientName = arguments["name"] as? String else {return} @@ -368,6 +377,18 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand return false; } + + func answerCall(callInvite: CallInvite) { + let answerCallAction = CXAnswerCallAction(call: callInvite.uuid) + let transaction = CXTransaction(action: answerCallAction) + + callKitCallController.request(transaction) { error in + if let error = error { + self.sendPhoneCallEvents(description: "LOG|AnswerCallAction transaction request failed: \(error.localizedDescription)", isError: false) + return + } + } + } func makeCall(to: String) {