Skip to content

Commit f7fdc98

Browse files
authored
Merge pull request #281 from cybex-dev/fix_ios_answer_hangup
Fix: iOS call answer & hangup
2 parents b1f1d1b + 8791fb7 commit f7fdc98

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 0.3.1
22

3+
* Fix: [iOS] Fix `hangUp()` not ending incoming call when call is ringing. [Issue #244](https://github.com/cybex-dev/twilio_voice/issues/244)
4+
* Feat: [iOS] Add missing `answer()` native implementation. [Issue #244](https://github.com/cybex-dev/twilio_voice/issues/244)
35
* Feat: Add raw `Connect({Map<String, dynamic>?})` for all platforms
46
* Refactor: [Web] Removed unused `web_callkit` event listeners.
57
* 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`).

ios/Classes/SwiftTwilioVoicePlugin.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,14 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
268268
eventSink(!isOnHold ? "Hold" : "Unhold")
269269
}
270270
else if flutterCall.method == "answer" {
271-
// nuthin
271+
if(self.callInvite != nil) {
272+
let ci = self.callInvite!
273+
self.sendPhoneCallEvents(description: "LOG|answer method invoked", isError: false)
274+
self.answerCall(callInvite: ci)
275+
} else {
276+
let ferror: FlutterError = FlutterError(code: "ANSWER_ERROR", message: "No call invite to answer", details: nil)
277+
_result!(ferror)
278+
}
272279
}
273280
else if flutterCall.method == "unregister" {
274281
guard let deviceToken = deviceToken else {
@@ -287,6 +294,8 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
287294
self.userInitiatedDisconnect = true
288295
performEndCallAction(uuid: self.call!.uuid!)
289296
//self.toggleUIState(isEnabled: false, showCallControl: false)
297+
} else if(self.callInvite != nil) {
298+
performEndCallAction(uuid: self.callInvite!.uuid)
290299
}
291300
}else if flutterCall.method == "registerClient"{
292301
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
368377

369378
return false;
370379
}
380+
381+
func answerCall(callInvite: CallInvite) {
382+
let answerCallAction = CXAnswerCallAction(call: callInvite.uuid)
383+
let transaction = CXTransaction(action: answerCallAction)
384+
385+
callKitCallController.request(transaction) { error in
386+
if let error = error {
387+
self.sendPhoneCallEvents(description: "LOG|AnswerCallAction transaction request failed: \(error.localizedDescription)", isError: false)
388+
return
389+
}
390+
}
391+
}
371392

372393
func makeCall(to: String)
373394
{

0 commit comments

Comments
 (0)