Search code examples
iosswifttwiliocallkit

CallKit error 7 when I perform a call for the first time


I've done a call kit + twilio IOS app. The problem is (as far as I can tell) with ios 12.

When I run the app on a device with IOS 11 the call start as normal. When I run the app on a device with IOS 12, when I try to make the first call I get this error :

  StartCallAction transaction request failed: The operation couldn’t be 
  completed. (com.apple.CallKit.error.requesttransaction error 7.)

This error represent this: The requested transaction contains actions that, if performed, would exceed the maximum number of call groups for the provider. But i set the callGroupMax number to 1 ( I tried to set it 2,3 but still the same)

I found just one thread with this error on google but no solution was provided. Pleas give me a hint on what causes this error because I'm stuck on this.

This error appears only when the first call is made after a fresh install. Then I can make calls as it was intended.

This is the callkitManager class:

class CallKitManager: NSObject {
    class var shared: CallKitManager {
        struct Static {
            static let instance: CallKitManager = CallKitManager()
        }
        return Static.instance
    }

    fileprivate let callKitProvider: CXProvider

    override init() {
        callKitProvider = CXProvider(configuration: type(of: self).providerConfiguration)
        super.init()
        callKitProvider.setDelegate(self, queue: nil)
    }

    static var providerConfiguration: CXProviderConfiguration {
        let localizedName                      = NSLocalizedString("NAME", comment: "Name of application")
        let configuration                      = CXProviderConfiguration(localizedName: localizedName)
        configuration.supportsVideo            = false
        configuration.maximumCallsPerCallGroup = 1
        configuration.ringtoneSound            = "myringtone"
        configuration.supportedHandleTypes     = [.generic]

        if let callKitIcon = UIImage(named: "callKitIcon") {
            configuration.iconTemplateImageData = callKitIcon.pngData()
        }

        return configuration
    }

I expect that the call to connect from the first time, but the result is that in the performStartCallAction() method I get the error from above.


Solution

  • So after 2 days I figure it out. The problem was that I use the callKit as a singleton which is wrong. You need "to mimic" a singleton using AppDelegate. See this tutorial https://www.raywenderlich.com/701-callkit-tutorial-for-ios and look in the AppDelegate and se how this was implemented.