$npx -y skills add dpearson2699/swift-ios-skills --skill callkitImplement VoIP calling with CallKit and PushKit. Use when building incoming/outgoing call flows, registering for VoIP push notifications, configuring CXProvider and CXCallController, handling call actions, coordinating audio sessions, or creating Call Directory extensions for cal
| 1 | # CallKit |
| 2 | |
| 3 | Build VoIP calling features that integrate with the native iOS call UI using |
| 4 | CallKit and PushKit. Covers incoming/outgoing call flows, VoIP push |
| 5 | registration, audio session coordination, and call directory extensions. |
| 6 | |
| 7 | ## Contents |
| 8 | |
| 9 | - [Setup](#setup) |
| 10 | - [Provider Configuration](#provider-configuration) |
| 11 | - [Incoming Call Flow](#incoming-call-flow) |
| 12 | - [Outgoing Call Flow](#outgoing-call-flow) |
| 13 | - [PushKit VoIP Registration](#pushkit-voip-registration) |
| 14 | - [Audio Session Coordination](#audio-session-coordination) |
| 15 | - [Call Directory Extension and Manager](#call-directory-extension-and-manager) |
| 16 | - [Common Mistakes](#common-mistakes) |
| 17 | - [Review Checklist](#review-checklist) |
| 18 | - [References](#references) |
| 19 | |
| 20 | ## Setup |
| 21 | |
| 22 | ### Project Configuration |
| 23 | |
| 24 | 1. Enable the **Voice over IP** background mode in Signing & Capabilities |
| 25 | 2. Add the **Push Notifications** capability |
| 26 | 3. For call directory extensions, add a **Call Directory Extension** target |
| 27 | |
| 28 | ### Key Types |
| 29 | |
| 30 | | Type | Role | |
| 31 | |---|---| |
| 32 | | `CXProvider` | Reports calls to the system, receives call actions | |
| 33 | | `CXCallController` | Requests call actions (start, end, hold, mute) | |
| 34 | | `CXCallUpdate` | Describes call metadata (caller name, video, handle) | |
| 35 | | `CXProviderDelegate` | Handles system call actions and audio session events | |
| 36 | | `PKPushRegistry` | Registers for and receives VoIP push notifications | |
| 37 | | `PKVoIPPushMetadata` | iOS 26.4+ metadata that says whether a VoIP push must be reported | |
| 38 | |
| 39 | ## Provider Configuration |
| 40 | |
| 41 | Create a single `CXProvider` at app launch and keep it alive for the app |
| 42 | lifetime. Configure it with a `CXProviderConfiguration` that describes your |
| 43 | calling capabilities. |
| 44 | |
| 45 | ```swift |
| 46 | import CallKit |
| 47 | |
| 48 | /// CXProvider dispatches all delegate calls to the queue passed to `setDelegate(_:queue:)`. |
| 49 | /// The `let` properties are initialized once and never mutated, making this type |
| 50 | /// safe to share across concurrency domains despite @unchecked Sendable. |
| 51 | final class CallManager: NSObject, @unchecked Sendable { |
| 52 | static let shared = CallManager() |
| 53 | |
| 54 | let provider: CXProvider |
| 55 | let callController = CXCallController() |
| 56 | |
| 57 | private override init() { |
| 58 | let config = CXProviderConfiguration() |
| 59 | config.localizedName = "My VoIP App" |
| 60 | config.supportsVideo = true |
| 61 | config.maximumCallsPerCallGroup = 1 |
| 62 | config.maximumCallGroups = 2 |
| 63 | config.supportedHandleTypes = [.phoneNumber, .emailAddress] |
| 64 | config.includesCallsInRecents = true |
| 65 | |
| 66 | provider = CXProvider(configuration: config) |
| 67 | super.init() |
| 68 | provider.setDelegate(self, queue: nil) |
| 69 | } |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | ## Incoming Call Flow |
| 74 | |
| 75 | When a required VoIP call push arrives, report the incoming call to CallKit |
| 76 | immediately. The system displays the native call UI. You must report required |
| 77 | calls before the PushKit completion handler returns -- failure to do so causes |
| 78 | the system to terminate your app. |
| 79 | |
| 80 | ```swift |
| 81 | func reportIncomingCall( |
| 82 | uuid: UUID, |
| 83 | handle: String, |
| 84 | hasVideo: Bool |
| 85 | ) async throws { |
| 86 | let update = CXCallUpdate() |
| 87 | update.remoteHandle = CXHandle(type: .phoneNumber, value: handle) |
| 88 | update.hasVideo = hasVideo |
| 89 | update.localizedCallerName = "Jane Doe" |
| 90 | |
| 91 | try await withCheckedThrowingContinuation { |
| 92 | (continuation: CheckedContinuation<Void, Error>) in |
| 93 | provider.reportNewIncomingCall( |
| 94 | with: uuid, |
| 95 | update: update |
| 96 | ) { error in |
| 97 | if let error { |
| 98 | continuation.resume(throwing: error) |
| 99 | } else { |
| 100 | continuation.resume() |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | ``` |
| 106 | |
| 107 | ### Handling the Answer Action |
| 108 | |
| 109 | Implement `CXProviderDelegate` to respond when the user answers: |
| 110 | |
| 111 | ```swift |
| 112 | extension CallManager: CXProviderDelegate { |
| 113 | func providerDidReset(_ provider: CXProvider) { |
| 114 | // End all calls, reset audio |
| 115 | } |
| 116 | |
| 117 | func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { |
| 118 | // Prepare audio, then fulfill only after the call is actually ready |
| 119 | configureAudioSession() |
| 120 | connectToCallServer(callUUID: action.callUUID) { success in |
| 121 | if success { |
| 122 | action.fulfill() |
| 123 | } else { |
| 124 | provider.reportCall( |
| 125 | with: action.callUUID, |
| 126 | endedAt: Date(), |
| 127 | reason: .failed |
| 128 | ) |
| 129 | action.fail() |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func provider(_ provider: CXProvider, perform action: CXEndCallAction) { |
| 135 | disconnectFromCallServer(callUUID: action.callUUID) |
| 136 | action.fulfill() |
| 137 | } |
| 138 | } |
| 139 | ``` |
| 140 | |
| 141 | ## Outgoing Call Flow |
| 142 | |
| 143 | Use `CXCallController` to request an outgoing call. The system routes the |
| 144 | request through your `C |