@@ -268,7 +268,14 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
268
268
eventSink ( !isOnHold ? " Hold " : " Unhold " )
269
269
}
270
270
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
+ }
272
279
}
273
280
else if flutterCall. method == " unregister " {
274
281
guard let deviceToken = deviceToken else {
@@ -287,6 +294,8 @@ public class SwiftTwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHand
287
294
self . userInitiatedDisconnect = true
288
295
performEndCallAction ( uuid: self . call!. uuid!)
289
296
//self.toggleUIState(isEnabled: false, showCallControl: false)
297
+ } else if ( self . callInvite != nil ) {
298
+ performEndCallAction ( uuid: self . callInvite!. uuid)
290
299
}
291
300
} else if flutterCall. method == " registerClient " {
292
301
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
368
377
369
378
return false ;
370
379
}
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
+ }
371
392
372
393
func makeCall( to: String )
373
394
{
0 commit comments