Back to the playbook
Chapter 03 · 5 min read

CallKit + FaceID: the 2-second audio gap

Locked devices eat the opening of every call. Here's why — and how to pre-warm the media path.

CallKitPushKitFaceIDlifecycle

The bug.

Device is locked. VoIP push arrives. You report to CallKit. The native ring plays. The user Face-IDs in, taps the green button — and hears nothing for the first 1-2 seconds. By the time they say “hello?” they've already decided your app is broken.

The painful part: the connection is fine. SDP is negotiated. ICE is connected. Media packets are arriving. The AudioSession is correctly configured. But audio hardware is deaf for ~1500ms after unlock. The user hears silence; your logs show everything green.

What's actually happening.

iOS has three gates between a locked device and a working call:

  1. CallKit report — the OS-level ring. Must happen within ~20 seconds of your PushKit payload or you get killed.
  2. User authentication — Face ID / Touch ID / passcode. Takes 0.3-2 seconds depending on glance angle and whether your hands are warm.
  3. UI foregrounding + media activation — your app comes to foreground, your call UI mounts, your media activates.

The default pattern is to do steps 1 → 2 → 3 in order. CallKit rings, the user unlocks, then your app wakes properly and starts the peer connection. That's the bug. By the time the peer finishes ICE and starts flowing media, the user has been staring at a “Connected” UI for a second.

The fix: pre-warm the media path.

CallKit reporting and media preparation can happen in parallel. You don't need the user authenticated to run ICE gathering, open the audio session, or set up the peer connection. Nothing about those operations needs the screen unlocked.

So decouple them. The moment reportNewIncomingCall succeeds, kick off media prep on a detached Task. By the time the user Face-IDs in, you're already connected and audio flows the instant they tap answer.

CallKitReport.swift
1// VoIP push arrives — three things happen in parallel.
2// Order matters INSIDE each column, not between them.
3//
4// ┌─────────────────┐ ┌─────────────────────┐ ┌──────────────────────┐
5// │ CallKit (sync) │ │ Peer prep (async) │ │ User auth (iOS owns)│
6// │ 1. report │ │ 1. configure peer │ │ 1. Face ID prompt │
7// │ 2. wait for user│ │ 2. gather ICE │ │ 2. unlock │
8// └─────────────────┘ │ 3. ready for answer │ │ 3. tap green button │
9// └─────────────────────┘ └──────────────────────┘
10 
11provider.reportNewIncomingCall(with: uuid, update: update) { reportError in
12 guard reportError == nil else { return }
13 
14 // Pre-warm media NOW — the user is still Face-IDing.
15 Task.detached(priority: .userInitiated) { [weak self] in
16 guard let self else { return }
17 do {
18 try await self.peer.setConfiguration(self.iceConfig)
19 try await self.peer.prepareForMedia() // creates DC, gathers ICE
20 try await self.signaling.negotiate(.offer) // SDP exchange
21 // Peer is now at .connected. Audio session stays inactive until answer.
22 } catch {
23 Analytics.breadcrumb("prewarm.failed", error: error)
24 }
25 }
26}
27 
28// Elsewhere — CXProviderDelegate
29func provider(_: CXProvider, perform action: CXAnswerCallAction) {
30 let session = AVAudioSession.sharedInstance()
31 try? session.setCategory(.playAndRecord,
32 mode: .voiceChat,
33 options: [.allowBluetooth, .allowBluetoothA2DP])
34 try? session.setActive(true, options: [.notifyOthersOnDeactivation])
35 // Media flows the moment session.active == true, because the peer is ready.
36 action.fulfill()
37}

The nuances that will bite you.

1. You can't touch AVAudioSession active state until the user accepts.

Setting the audio session active = true on a locked device fails with AVAudioSession.ErrorCode.cannotStartPlaying. That's by design — Apple doesn't want your app grabbing the mic while the user is asleep. So the pre-warm covers everything except session activation.

Session activation moves to the CXAnswerCallAction handler, which fires the instant the user accepts. By then ICE is done and the peer connection is sitting at connected; activation takes ~50ms and media flows.

2. If the user declines, you did a bunch of work for nothing.

That's fine. You tear it down in the CXEndCallAction handler and move on. The alternative — not pre-warming — makes every accepted call feel broken to save CPU on the declined ones. Wrong tradeoff. People remember the broken calls.

3. Pre-warm must be bounded.

If the user never answers, your detached Task is still gathering ICE candidates and burning battery. Attach a withTimeout(seconds: 25) wrapper or cancel it from the CXEndCallAction handler. Both.

4. Measure, don't guess.

I added two Crashlytics breadcrumbs that log the deltas:

Before the fix, the second number averaged 1400ms. After, 110ms. Field numbers don't lie; test them on actual locked devices with Face ID enabled, not on an unlocked Simulator.

Why this is a system-design problem, not an iOS problem.

iOS gives you the primitives (PushKit, CallKit, AVAudioSession). It's up to you to compose them in parallel instead of in series. The reflex to do steps 1 → 2 → 3 sequentially comes from the imperative model you've been using for ten years. Swift's structured concurrency makes the parallel version shorter, not longer. Use it.

Related chapters.

If this chapter helped, you'll want Chapter 01: The cold-start silence (same shape of bug, different root cause) and Chapter 02: The SDP offer/answer race (what happens to this pre-warmed peer connection when the network blips mid-call).

The fix in this chapter is from production at YEO Messaging. Measured on a mix of iPhone 12 through 15 Pro, iOS 16 through 17. Numbers vary by device; the pattern doesn't.