The cold-start silence
When PushKit wakes your app but the call connects mute.
The bug, in one sentence.
VoIP push arrives, CallKit presents the call UI, the user picks up — and the first two seconds of audio are gone. Then it recovers. Sometimes.
I spent a week chasing this at YEO Messaging. The symptom came and went based on whether the app had been in memory or launched cold. Users on long sessions never saw it. Users receiving the first call of the day always did.
Why it happens.
When your app is terminated and a VoIP push wakes it, iOS gives you a strict budget — about 20 seconds — to report the incoming call to CallKit via reportNewIncomingCall. Miss that, and the system kills you. So the reflex is to race to report: the first thing your PKPushRegistryDelegate does is call CallKit.
That's correct for CallKit. It's wrong for audio.
Audio on iOS is governed by AVAudioSession. Before anyRTCPeerConnection can push PCM frames into the output mixer, you must have set a category that permits playback and recording (usually .playAndRecord with mode .voiceChat), and you must have set the session active. Both of those are synchronous — but “active” triggers a hardware route negotiation that can take 50-150ms, and during that window, any media the peer sends you is dropped on the floor.
In the cold-start path, here's the race in slow motion:
- t=0ms: VoIP push wakes the process.
- t=5ms: You report to CallKit. ✅
- t=10ms: Signaling connects. SDP offer is sent to the server.
- t=80ms: Peer receives the offer, answers immediately. Media starts flowing.
- t=120ms: You remember to activate the audio session.
- t=250ms: Audio hardware actually ready. Media from the last 170ms is already gone.
The fix.
Activate AVAudioSession before the first SDP offer leaves the device. Not before CallKit — CallKit must still be first for the OS-kill budget. But between CallKit and the peer: activate the session, synchronously, with the voice chat category.
1// Order matters.2// 1. Report to CallKit (OS-kill budget)3// 2. Activate audio (so media has somewhere to go)4// 3. Send the offer (so the peer can start sending)56provider.reportNewIncomingCall(with: uuid, update: update) { reportError in7 guard reportError == nil else { return }89 let session = AVAudioSession.sharedInstance()10 try? session.setCategory(.playAndRecord,11 mode: .voiceChat,12 options: [.allowBluetooth, .allowBluetoothA2DP])13 try? session.setActive(true, options: [.notifyOthersOnDeactivation])1415 // Only now — once media I/O is live — send the offer.16 Task {17 let sdp = try await peer.offer()18 try await peer.setLocalDescription(sdp)19 signaling.send(.offer(sdp))20 }21}
Three things matter in that snippet:
- Category before active. Setting the category after activating the session is a no-op in terms of ordering guarantees — the system can start the hardware with the wrong defaults.
.notifyOthersOnDeactivation. Not strictly required for the bug, but it makes you a good citizen: when the call ends, music apps resume.- Await the local description. Only after
setLocalDescriptionresolves do you signal the offer out. If you send the offer before local SDP is set, the peer may answer before the local side is ready and you'll seesetRemoteDescriptionfail with an invalid state.
How to make it stay fixed.
The hard part of this bug isn't writing the fix — it's preventing it from regressing. The ordering constraint lives in your head, not in the type system. Here's the regression test harness I'd set up:
- Add a release-mode assertion that logs if any peer connection reaches
connectedstate beforeAVAudioSessionis active. Not a crash — a Crashlytics log event. You want to see the regression in the field. - Create a
CallBootentry point in your app. Make the terminated-state launch path the same code path as the warm-foreground path. Any divergence is where the bug comes back. - Automate it. Terminate the app from the Simulator, send a VoIP push via the
simctl pushcommand, assert audio is live within 300ms ofreportNewIncomingCall.
Related chapters.
If you're working on the same stack, the next two bugs you'll hit are the CallKit + FaceID race (locked-device audio gap) and the SDP offer/answer race under reconnect. Both are in this playbook.
Everything in this chapter is drawn from production work at YEO Messaging (UK). The code is simplified from the real patch — the real patch has three more branches for AirPods vs CarPlay vs built-in receiver, which I'll cover in the Bluetooth chapter.