jacob
jacob

Reputation: 1052

How to set timeout for CallKit incoming call UI

I'm developing Video call feature in my app and using CallKit to be the incoming call UI. And i found an edge case like:

So is there any way to set a timeout for an incoming UI of CallKit? For example: If i set the timeout is 60 seconds then the incoming UI just shows in 60 seconds the auto dismiss.

Here is my code to show the incoming UI:

let update = CXCallUpdate()
update.localizedCallerName = callerName
update.remoteHandle = CXHandle(type: .phoneNumber, value: myID)
update.hasVideo = true
        
self.provider.reportNewIncomingCall(with: uuid, update: update) { [weak self] error in
    guard let self = self else { return }
    if error == nil {
        // Store my calls
        let call = Call(uuid: uuid, handle: handle)
        self.callKitManager.add(call: call)
    }
}

Any help would be greatly appreciated. Thanks.

Upvotes: 2

Views: 1740

Answers (1)

Marco
Marco

Reputation: 1686

There's no way to set a timeout using the CallKit API. You just have to implement it by yourself.

In the class where you handle all the call logic, you should add something like the following:

private func startRingingTimer(for call: Call)
{
    let vTimer = Timer(
        timeInterval: 60,
        repeats: false,
        block: { [weak self] _ in
            self?.ringingDidTimeout(for: call)
        })
    vTimer.tolerance = 0.5
    RunLoop.current.add(vTimer, forMode: .common)
    ringingTimer = vTimer
}

private func ringingDidTimeout(for call: Call)
{
    ...
    self.provider.reportCall(with: call.uuid, endedAt: nil, reason: .unanswered)
    ...
}

Then you should call startRingingTimer(for: call) as soon as you successfully reported a new incoming call; and, of course, you have to invalidate the timer if the user answers the call.

Upvotes: 3

Related Questions