Audio seems not work with CallKit when incoming call is answered












1















I integrated my app with CallKit in order to receive incoming call from another user using VoIP. Now i am facing some issue with audio which it cannot be activated when call is answered.



I have checked with this tutorial This and i have compared ProviderDelegate which is quite similar.



This is how my ProviderDelegate class looks like



class ProviderDelegate: NSObject {
// 1.
fileprivate let callKitManager: CallKitCallInit
fileprivate let provider: CXProvider

init(callKitManager: CallKitCallInit) {
self.callKitManager = callKitManager
// 2.
provider = CXProvider(configuration: type(of: self).providerConfiguration)

super.init()
// 3.
provider.setDelegate(self, queue: nil)

}

// 4.
static var providerConfiguration: CXProviderConfiguration {
let providerConfiguration = CXProviderConfiguration(localizedName: "vKclub dev2")

providerConfiguration.supportsVideo = false
providerConfiguration.maximumCallsPerCallGroup = 1
providerConfiguration.supportedHandleTypes = [.phoneNumber]
return providerConfiguration
}

func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {
// 1.
print("This is UUID === ", uuid)
configureAudioSession()
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
update.hasVideo = hasVideo


provider.reportNewIncomingCall(with: uuid, update: update) { error in


if error == nil {

self.configureAudioSession()
let call = CallKitCallInit(uuid: uuid, handle: handle)
self.callKitManager.add(call: call)
lastCallUUID = uuid
print("UUID === ", uuid)
} else {

}


completion?(error as NSError?)
}


}

}


This is how i setup AVAudioSession



extension ProviderDelegate: CXProviderDelegate {

func providerDidReset(_ provider: CXProvider) {
print("Stop Audio ==STOP-AUDIO==")

for call in callKitManager.calls {
call.end(uuid: UUID())
}

callKitManager.removeAllCalls()
}
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
// 1.
guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
action.fail()
return
}

configureAudioSession()

}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
// 1.
guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
action.fail()
return
}
// 2.
configureAudioSession()
// 3.
call.answer()
// 4.
if #available(iOS 11, *) {
print ("vKclub")
} else {

action.fulfill()
}

}

func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
// 1.
guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
action.fail()
return
}
// 2.
print("Stop audio ==STOP-AUDIO==")
configureAudioSession()
// 3.
call.end(uuid: action.callUUID)
// 4.
if #available(iOS 11, *) {
print("Our vKclube")
} else {
action.fulfill()
}

// 5.
callKitManager.remove(call: call)
}

// 5.
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
print("Starting audio ==STARTING-AUDIO==")
}


func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
print("Received (#function)")
}

func configureAudioSession() {
let session = AVAudioSession.sharedInstance()

do{
try session.setCategory(AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVoiceChat,
options: )

} catch {
print("========== Error in setting category (error.localizedDescription)")
}

do {
try session.setPreferredSampleRate(44100.0)
} catch {
print("======== Error setting rate (error.localizedDescription)")
}
do {
try session.setPreferredIOBufferDuration(0.005)
} catch {
print("======== Error IOBufferDuration (error.localizedDescription)")
}
do {
try session.setActive(true)
} catch {
print("========== Error starting session (error.localizedDescription)")
}
}


}



I have been facing this issue for several days already still i cannot figure it out.
I am using XCode 10.1.










share|improve this question



























    1















    I integrated my app with CallKit in order to receive incoming call from another user using VoIP. Now i am facing some issue with audio which it cannot be activated when call is answered.



    I have checked with this tutorial This and i have compared ProviderDelegate which is quite similar.



    This is how my ProviderDelegate class looks like



    class ProviderDelegate: NSObject {
    // 1.
    fileprivate let callKitManager: CallKitCallInit
    fileprivate let provider: CXProvider

    init(callKitManager: CallKitCallInit) {
    self.callKitManager = callKitManager
    // 2.
    provider = CXProvider(configuration: type(of: self).providerConfiguration)

    super.init()
    // 3.
    provider.setDelegate(self, queue: nil)

    }

    // 4.
    static var providerConfiguration: CXProviderConfiguration {
    let providerConfiguration = CXProviderConfiguration(localizedName: "vKclub dev2")

    providerConfiguration.supportsVideo = false
    providerConfiguration.maximumCallsPerCallGroup = 1
    providerConfiguration.supportedHandleTypes = [.phoneNumber]
    return providerConfiguration
    }

    func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {
    // 1.
    print("This is UUID === ", uuid)
    configureAudioSession()
    let update = CXCallUpdate()
    update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
    update.hasVideo = hasVideo


    provider.reportNewIncomingCall(with: uuid, update: update) { error in


    if error == nil {

    self.configureAudioSession()
    let call = CallKitCallInit(uuid: uuid, handle: handle)
    self.callKitManager.add(call: call)
    lastCallUUID = uuid
    print("UUID === ", uuid)
    } else {

    }


    completion?(error as NSError?)
    }


    }

    }


    This is how i setup AVAudioSession



    extension ProviderDelegate: CXProviderDelegate {

    func providerDidReset(_ provider: CXProvider) {
    print("Stop Audio ==STOP-AUDIO==")

    for call in callKitManager.calls {
    call.end(uuid: UUID())
    }

    callKitManager.removeAllCalls()
    }
    func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
    // 1.
    guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
    action.fail()
    return
    }

    configureAudioSession()

    }
    func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    // 1.
    guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
    action.fail()
    return
    }
    // 2.
    configureAudioSession()
    // 3.
    call.answer()
    // 4.
    if #available(iOS 11, *) {
    print ("vKclub")
    } else {

    action.fulfill()
    }

    }

    func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
    // 1.
    guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
    action.fail()
    return
    }
    // 2.
    print("Stop audio ==STOP-AUDIO==")
    configureAudioSession()
    // 3.
    call.end(uuid: action.callUUID)
    // 4.
    if #available(iOS 11, *) {
    print("Our vKclube")
    } else {
    action.fulfill()
    }

    // 5.
    callKitManager.remove(call: call)
    }

    // 5.
    func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
    print("Starting audio ==STARTING-AUDIO==")
    }


    func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
    print("Received (#function)")
    }

    func configureAudioSession() {
    let session = AVAudioSession.sharedInstance()

    do{
    try session.setCategory(AVAudioSessionCategoryPlayAndRecord,
    mode: AVAudioSessionModeVoiceChat,
    options: )

    } catch {
    print("========== Error in setting category (error.localizedDescription)")
    }

    do {
    try session.setPreferredSampleRate(44100.0)
    } catch {
    print("======== Error setting rate (error.localizedDescription)")
    }
    do {
    try session.setPreferredIOBufferDuration(0.005)
    } catch {
    print("======== Error IOBufferDuration (error.localizedDescription)")
    }
    do {
    try session.setActive(true)
    } catch {
    print("========== Error starting session (error.localizedDescription)")
    }
    }


    }



    I have been facing this issue for several days already still i cannot figure it out.
    I am using XCode 10.1.










    share|improve this question

























      1












      1








      1


      1






      I integrated my app with CallKit in order to receive incoming call from another user using VoIP. Now i am facing some issue with audio which it cannot be activated when call is answered.



      I have checked with this tutorial This and i have compared ProviderDelegate which is quite similar.



      This is how my ProviderDelegate class looks like



      class ProviderDelegate: NSObject {
      // 1.
      fileprivate let callKitManager: CallKitCallInit
      fileprivate let provider: CXProvider

      init(callKitManager: CallKitCallInit) {
      self.callKitManager = callKitManager
      // 2.
      provider = CXProvider(configuration: type(of: self).providerConfiguration)

      super.init()
      // 3.
      provider.setDelegate(self, queue: nil)

      }

      // 4.
      static var providerConfiguration: CXProviderConfiguration {
      let providerConfiguration = CXProviderConfiguration(localizedName: "vKclub dev2")

      providerConfiguration.supportsVideo = false
      providerConfiguration.maximumCallsPerCallGroup = 1
      providerConfiguration.supportedHandleTypes = [.phoneNumber]
      return providerConfiguration
      }

      func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {
      // 1.
      print("This is UUID === ", uuid)
      configureAudioSession()
      let update = CXCallUpdate()
      update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
      update.hasVideo = hasVideo


      provider.reportNewIncomingCall(with: uuid, update: update) { error in


      if error == nil {

      self.configureAudioSession()
      let call = CallKitCallInit(uuid: uuid, handle: handle)
      self.callKitManager.add(call: call)
      lastCallUUID = uuid
      print("UUID === ", uuid)
      } else {

      }


      completion?(error as NSError?)
      }


      }

      }


      This is how i setup AVAudioSession



      extension ProviderDelegate: CXProviderDelegate {

      func providerDidReset(_ provider: CXProvider) {
      print("Stop Audio ==STOP-AUDIO==")

      for call in callKitManager.calls {
      call.end(uuid: UUID())
      }

      callKitManager.removeAllCalls()
      }
      func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
      // 1.
      guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
      action.fail()
      return
      }

      configureAudioSession()

      }
      func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
      // 1.
      guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
      action.fail()
      return
      }
      // 2.
      configureAudioSession()
      // 3.
      call.answer()
      // 4.
      if #available(iOS 11, *) {
      print ("vKclub")
      } else {

      action.fulfill()
      }

      }

      func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
      // 1.
      guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
      action.fail()
      return
      }
      // 2.
      print("Stop audio ==STOP-AUDIO==")
      configureAudioSession()
      // 3.
      call.end(uuid: action.callUUID)
      // 4.
      if #available(iOS 11, *) {
      print("Our vKclube")
      } else {
      action.fulfill()
      }

      // 5.
      callKitManager.remove(call: call)
      }

      // 5.
      func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
      print("Starting audio ==STARTING-AUDIO==")
      }


      func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
      print("Received (#function)")
      }

      func configureAudioSession() {
      let session = AVAudioSession.sharedInstance()

      do{
      try session.setCategory(AVAudioSessionCategoryPlayAndRecord,
      mode: AVAudioSessionModeVoiceChat,
      options: )

      } catch {
      print("========== Error in setting category (error.localizedDescription)")
      }

      do {
      try session.setPreferredSampleRate(44100.0)
      } catch {
      print("======== Error setting rate (error.localizedDescription)")
      }
      do {
      try session.setPreferredIOBufferDuration(0.005)
      } catch {
      print("======== Error IOBufferDuration (error.localizedDescription)")
      }
      do {
      try session.setActive(true)
      } catch {
      print("========== Error starting session (error.localizedDescription)")
      }
      }


      }



      I have been facing this issue for several days already still i cannot figure it out.
      I am using XCode 10.1.










      share|improve this question














      I integrated my app with CallKit in order to receive incoming call from another user using VoIP. Now i am facing some issue with audio which it cannot be activated when call is answered.



      I have checked with this tutorial This and i have compared ProviderDelegate which is quite similar.



      This is how my ProviderDelegate class looks like



      class ProviderDelegate: NSObject {
      // 1.
      fileprivate let callKitManager: CallKitCallInit
      fileprivate let provider: CXProvider

      init(callKitManager: CallKitCallInit) {
      self.callKitManager = callKitManager
      // 2.
      provider = CXProvider(configuration: type(of: self).providerConfiguration)

      super.init()
      // 3.
      provider.setDelegate(self, queue: nil)

      }

      // 4.
      static var providerConfiguration: CXProviderConfiguration {
      let providerConfiguration = CXProviderConfiguration(localizedName: "vKclub dev2")

      providerConfiguration.supportsVideo = false
      providerConfiguration.maximumCallsPerCallGroup = 1
      providerConfiguration.supportedHandleTypes = [.phoneNumber]
      return providerConfiguration
      }

      func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {
      // 1.
      print("This is UUID === ", uuid)
      configureAudioSession()
      let update = CXCallUpdate()
      update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
      update.hasVideo = hasVideo


      provider.reportNewIncomingCall(with: uuid, update: update) { error in


      if error == nil {

      self.configureAudioSession()
      let call = CallKitCallInit(uuid: uuid, handle: handle)
      self.callKitManager.add(call: call)
      lastCallUUID = uuid
      print("UUID === ", uuid)
      } else {

      }


      completion?(error as NSError?)
      }


      }

      }


      This is how i setup AVAudioSession



      extension ProviderDelegate: CXProviderDelegate {

      func providerDidReset(_ provider: CXProvider) {
      print("Stop Audio ==STOP-AUDIO==")

      for call in callKitManager.calls {
      call.end(uuid: UUID())
      }

      callKitManager.removeAllCalls()
      }
      func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
      // 1.
      guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
      action.fail()
      return
      }

      configureAudioSession()

      }
      func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
      // 1.
      guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
      action.fail()
      return
      }
      // 2.
      configureAudioSession()
      // 3.
      call.answer()
      // 4.
      if #available(iOS 11, *) {
      print ("vKclub")
      } else {

      action.fulfill()
      }

      }

      func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
      // 1.
      guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
      action.fail()
      return
      }
      // 2.
      print("Stop audio ==STOP-AUDIO==")
      configureAudioSession()
      // 3.
      call.end(uuid: action.callUUID)
      // 4.
      if #available(iOS 11, *) {
      print("Our vKclube")
      } else {
      action.fulfill()
      }

      // 5.
      callKitManager.remove(call: call)
      }

      // 5.
      func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
      print("Starting audio ==STARTING-AUDIO==")
      }


      func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
      print("Received (#function)")
      }

      func configureAudioSession() {
      let session = AVAudioSession.sharedInstance()

      do{
      try session.setCategory(AVAudioSessionCategoryPlayAndRecord,
      mode: AVAudioSessionModeVoiceChat,
      options: )

      } catch {
      print("========== Error in setting category (error.localizedDescription)")
      }

      do {
      try session.setPreferredSampleRate(44100.0)
      } catch {
      print("======== Error setting rate (error.localizedDescription)")
      }
      do {
      try session.setPreferredIOBufferDuration(0.005)
      } catch {
      print("======== Error IOBufferDuration (error.localizedDescription)")
      }
      do {
      try session.setActive(true)
      } catch {
      print("========== Error starting session (error.localizedDescription)")
      }
      }


      }



      I have been facing this issue for several days already still i cannot figure it out.
      I am using XCode 10.1.







      ios swift voip avaudiosession callkit






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 13:26









      Visal SamboVisal Sambo

      260213




      260213
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I found the error is about your code action.fulfill() is never called.



          Based on document of Apple:



          Calling this method sets the isComplete property value to true. Calling this method more than once or calling it after calling the fail() method has no effect.
          You should only call this method from the implementation of a CXProviderDelegate method.



          I hope you should call this method inside CXProviderDelegate. I have seen you implemented it but sadly that method is never called. I am sure this is the reason why your audio is not activated.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007207%2faudio-seems-not-work-with-callkit-when-incoming-call-is-answered%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I found the error is about your code action.fulfill() is never called.



            Based on document of Apple:



            Calling this method sets the isComplete property value to true. Calling this method more than once or calling it after calling the fail() method has no effect.
            You should only call this method from the implementation of a CXProviderDelegate method.



            I hope you should call this method inside CXProviderDelegate. I have seen you implemented it but sadly that method is never called. I am sure this is the reason why your audio is not activated.






            share|improve this answer




























              1














              I found the error is about your code action.fulfill() is never called.



              Based on document of Apple:



              Calling this method sets the isComplete property value to true. Calling this method more than once or calling it after calling the fail() method has no effect.
              You should only call this method from the implementation of a CXProviderDelegate method.



              I hope you should call this method inside CXProviderDelegate. I have seen you implemented it but sadly that method is never called. I am sure this is the reason why your audio is not activated.






              share|improve this answer


























                1












                1








                1







                I found the error is about your code action.fulfill() is never called.



                Based on document of Apple:



                Calling this method sets the isComplete property value to true. Calling this method more than once or calling it after calling the fail() method has no effect.
                You should only call this method from the implementation of a CXProviderDelegate method.



                I hope you should call this method inside CXProviderDelegate. I have seen you implemented it but sadly that method is never called. I am sure this is the reason why your audio is not activated.






                share|improve this answer













                I found the error is about your code action.fulfill() is never called.



                Based on document of Apple:



                Calling this method sets the isComplete property value to true. Calling this method more than once or calling it after calling the fail() method has no effect.
                You should only call this method from the implementation of a CXProviderDelegate method.



                I hope you should call this method inside CXProviderDelegate. I have seen you implemented it but sadly that method is never called. I am sure this is the reason why your audio is not activated.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 14:22









                I Love CodingI Love Coding

                25517




                25517
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007207%2faudio-seems-not-work-with-callkit-when-incoming-call-is-answered%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas