๐ Pitel VoIP iOS SDK
A high-performance, native VoIP calling SDK for iOS applications, powered by PJSIP native core, native Apple CallKit, and Apple PushKit/APNs background push notifications.
- Physical iOS Device Required: A physical iOS device (iPhone/iPad) is strictly required to receive and test incoming VoIP calls. The iOS Simulator cannot generate valid PushKit APNs tokens and does not support receiving VoIP push notifications.
- Annual iOS VoIP Certificate Renewal: Apple VoIP Services Certificates (
.p12) expire every 1 year. You must renew the certificate annually on the Apple Developer Portal and re-upload the new.p12file to the Pitel SDK Portal periodically every year to avoid VoIP push notification disruptions.
๐ Documentation Indexโ
| Guide | Description |
|---|---|
| ๐ Quick Start Guide | 3-step plug & play integration with native Apple CallKit. |
| ๐ iOS VoIP Push & CallKit Setup | Native iOS configuration, PushKit APNs certificates, and AppDelegate setup. |
| ๐ Pitel Portal Setup Guide | Step-by-step guide to register Bundle ID, Team ID, and upload .p12 certificates. |
| ๐ฑ Sample Demo Project | Fully runnable iOS SwiftUI sample project with PushKit, CallKit, and in-call UI. |
| ๐ SIP Disconnect Codes Reference | Comprehensive SIP status code lookup table (486 Busy, 408 Timeout, 603 Decline...). |
| โ FAQ & 10 QA Test Cases Checklist | 10 real-world test scenarios for QA/Dev & solutions to common iOS CallKit pitfalls. |
| ๐ ๏ธ Troubleshooting Guide | Detailed resolution guide for Xcode build, linker, audio, and network issues. |
๐ System Requirementsโ
- iOS Version: iOS 14.0 or later
- Xcode Version: Xcode 13.0 or later
- Language: Swift 5.5+
- Architecture:
arm64(Physical Device)
๐ฆ Installationโ
1. Add PitelVoIPFramework (Swift Package Manager)โ
- In Xcode, select File โ Add Package Dependencies...
- Enter the official distribution repository URL:
https://github.com/voip-sdk/ios-pitel-voip-sdk.git - Set Dependency Rule to Up to Next Major Version (or specify latest version) and add PitelVoIPFramework to your target.
2. Add Required Firebase Dependenciesโ
The SDK uses Firebase Cloud Messaging for VoIP APNs token registration and push notification multiplexing:
- In Xcode, select File โ Add Package Dependencies...
- Enter the official Firebase iOS SDK repository URL:
https://github.com/firebase/firebase-ios-sdk.git - Add the following libraries to your target:
- โ FirebaseCore
- โ FirebaseMessaging
- Download your
GoogleService-Info.plistfrom the Firebase Console and drag it into your Xcode project root folder (ensure "Copy items if needed" and your target membership are checked).
๐ Quick Start (3-Step Integration)โ
Step 1: Configure Xcode Project Capabilities & Info.plistโ
1. Enable Capabilitiesโ
In your Xcode project, navigate to Target โ Signing & Capabilities:
- Click + Capability and add Push Notifications.
- Click + Capability and add Background Modes, then check:
- Voice over IP
- Remote notifications
- Audio, AirPlay, and Picture in Picture (optional for continuous background audio)
2. Configure Info.plistโ
Add background modes and microphone usage description to your Info.plist:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>fetch</string>
<string>remote-notification</string>
<string>voip</string>
</array>
<key>NSMicrophoneUsageDescription</key>
<string>This app requires access to the microphone to make and receive VoIP calls.</string>
Step 2: Configure AppDelegate.swiftโ
Inherit from PitelVoIPDelegate in your AppDelegate. The SDK automatically manages PushKit delegates, CallKit reporting, and audio session coordination:
import SwiftUI
import Firebase
import FirebaseMessaging
import PushKit
import PitelVoIPFramework
class AppDelegate: PitelVoIPDelegate, MessagingDelegate {
static let shared = AppDelegate()
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// 1. Initialize PitelVoIP SDK core (handles PushKit VoIP registration)
_ = super.application(application, didFinishLaunchingWithOptions: launchOptions)
// 2. Initialize Firebase Messaging
FirebaseApp.configure()
Messaging.messaging().delegate = self
// 3. Register presentation host provider so PitelCallView presents automatically over the active window
PitelVoIP.registerCallPresentationHostProvider {
guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = scene.windows.first(where: { $0.isKeyWindow }) ?? scene.windows.first else {
return nil
}
return window.rootViewController
}
return true
}
// Forward APNs token to Firebase Messaging
override func onAPNsTokenReceived(_ deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
// Deliver FCM token to PitelVoIP SDK
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let token = fcmToken {
onFCMTokenReceived(token)
}
}
// Handle remote notification fallback (VoIP push / background notification)
override func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
PitelVoIP.handleRemoteNotification(userInfo)
completionHandler(.newData)
}
}
Connect to SwiftUI App Lifecycle (If using SwiftUI)โ
In your @main App struct, wire up AppDelegate using @UIApplicationDelegateAdaptor and attach .pitelVoIPLifecycle() to automatically manage app resume and reconnection:
import SwiftUI
import PitelVoIPFramework
@main
struct YourApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
.pitelVoIPLifecycle(appDelegate: appDelegate)
}
}
}
Step 3: Login Extension & Register SIP Accountโ
Option A: Unified Login with Closure (Recommended)โ
This is the simplest way to configure and log in. The SDK handles delegate lookup, configuration building, and device token registration automatically:
PitelVoIP.login(
accountViewModel: AccountViewModel.shared ?? AccountViewModel(),
deviceTokenViewModel: .shared
) { builder in
builder
.setExtension("YOUR_EXTENSION")
.setPassword("YOUR_SIP_PASSWORD")
.setDomain("YOUR_SIP_DOMAIN")
.setProxy("sip:YOUR_PROXY_HOST:YOUR_PROXY_PORT")
.setPort("YOUR_SIP_REGISTRAR_PORT") // e.g. "50061"
.setDisplayName("YOUR_DISPLAY_NAME")
.setTeamId("YOUR_APPLE_TEAM_ID")
.setAppId("YOUR_BUNDLE_ID")
.setAppMode("production") // "dev" for Debug/Sandbox; "production" for TestFlight / App Store
.setUserAgent("YOUR_USER_AGENT") // Optional, e.g. "Pitel App" (default: "Pitel VoIP iOS")
}
Option B: Using PitelConfigBuilder Separatelyโ
If you prefer building the configuration object first (e.g. in your ViewModel or Coordinator):
let config = PitelConfigBuilder()
.setExtension("YOUR_EXTENSION")
.setPassword("YOUR_SIP_PASSWORD")
.setDomain("YOUR_SIP_DOMAIN")
.setProxy("sip:YOUR_PROXY_HOST:YOUR_PROXY_PORT")
.setPort("YOUR_SIP_REGISTRAR_PORT") // e.g. "50061"
.setDisplayName("YOUR_DISPLAY_NAME")
.setTeamId("YOUR_APPLE_TEAM_ID")
.setAppId("YOUR_BUNDLE_ID")
.setAppMode("production")
.setUserAgent("YOUR_USER_AGENT")
.build()
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.loginWithRegistration(
accountViewModel: AccountViewModel.shared ?? AccountViewModel(),
deviceTokenViewModel: DeviceTokenViewModel.shared,
sipInfo: config.sipInfo,
orgInfo: config.orgInfo
)
}
User-Agent Sanitization Rules:
- Default value:
"Pitel VoIP iOS"- Sanitization: Accented Vietnamese characters are converted to plain Latin (e.g.
แปจng dแปฅng->Ung dung). Special characters (@#$%^&*()) and CRLF characters (\r,\n) are removed.- Length limit: Maximum 30 characters (longer strings will be truncated).
- Fallback: If empty after sanitization, automatically falls back to
"Pitel VoIP iOS".
Step 4: Make an Outgoing Callโ
Construct the standard destination SIP URI (sip:ext@domain:port) and trigger the call via PitelVoIP.makeCall(...):
let destExt = "YOUR_TEST_DESTINATION_EXTENSION" // e.g., "103"
let domain = "YOUR_SIP_DOMAIN" // e.g., "ptc.tel4vn.com"
let port = "YOUR_SIP_REGISTRAR_PORT" // e.g., "50061"
// 1. Construct SIP URI
let outgoingCallId = "sip:\(destExt)@\(domain):\(port)"
// 2. Trigger Outgoing Call
PitelVoIP.makeCall(to: outgoingCallId, callerName: "Agent \(destExt)") { result in
switch result {
case .success:
print("โ
Call initiated successfully")
case .failure(let error):
print("โ Call failed: \(error.localizedDescription)")
}
}
When PitelVoIP.makeCall() is executed:
- Microphone permission is automatically requested if not yet granted.
- Native Apple CallKit registers the outgoing session.
- The built-in in-call screen (
PitelCallView) is automatically presented over your active window (configured in Step 2 viaregisterCallPresentationHostProvider). You do not need to manually push or present a view controller.
Step 5: Inbound Calls (Automatic CallKit & In-Call UI)โ
You do not need to build incoming call listeners or dialogs:
- When someone calls your extension, native Apple CallKit rings automatically (even if the app is killed or device is locked).
- Answering the call automatically activates system audio and presents the native
PitelCallView.
Step 6: Control Active Call (Optional Programmatic Actions)โ
All controls below (Mute, Speaker, Hold, Keypad/DTMF, Transfer, Hangup) are already built into the PitelCallView UI. You only need these APIs if triggering programmatic actions from outside the call screen.
// End call:
PitelVoIP.hangup()
// Mute / Unmute:
PitelVoIP.mute()
PitelVoIP.unmute()
// Hold / Unhold:
PitelVoIP.hold()
PitelVoIP.unhold()
// Send DTMF (e.g. interacting with an automated IVR menu):
let dtmfDigit = "YOUR_DTMF_DIGIT" // e.g., "1", "*", or "#"
PitelVoIP.sendDTMF(dtmfDigit)
// Blind Transfer active call to another extension:
let transferTarget = "sip:EXT@YOUR_SIP_DOMAIN:YOUR_SIP_REGISTRAR_PORT"
PitelVoIP.transferCall(to: transferTarget)
Step 7: Logout Extensionโ
To cleanly unregister from the PBX and remove push notification bindings:
if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
appDelegate.logoutWithUnregistration(
accountViewModel: AccountViewModel.shared ?? AccountViewModel(),
deviceTokenViewModel: DeviceTokenViewModel.shared,
sipInfo: currentSipInfo
)
}
๐งฉ Public iOS API Reference (PitelVoIP)โ
A concise cheat sheet of static methods exposed by PitelVoIP:
| Method | Parameters | Description |
|---|---|---|
PitelVoIP.configure(...) | PitelConfig? | Pre-configures SDK core before login. |
PitelVoIP.registerCallPresentationHostProvider(_:) | () -> UIViewController? | Registers root view controller for presenting native CallScreen. |
PitelVoIP.login(...) | accountViewModel, deviceTokenViewModel, configure: | Builds configuration and logs in SIP account with PushKit registration. |
PitelVoIP.logout(...) | accountViewModel, deviceTokenViewModel, sipInfo | Unregisters SIP extension and cleans up session. |
PitelVoIP.makeCall(to:callerName:completion:) | to: String, callerName: String?, completion: | Initiates an outbound VoIP call using standard SIP URI. |
PitelVoIP.hangup() | None | Terminates active call immediately. |
PitelVoIP.mute() | None | Mutes microphone. |
PitelVoIP.unmute() | None | Unmutes microphone. |
PitelVoIP.hold() | None | Holds current call. |
PitelVoIP.unhold() | None | Resumes held call. |
PitelVoIP.sendDTMF(_:) | String (0-9, *, #) | Sends DTMF tones during active call. |
PitelVoIP.transferCall(to:) | to: String | Blind transfers active call to target SIP URI. |
PitelVoIP.handleRemoteNotification(_:) | [AnyHashable: Any] | Processes incoming VoIP / background push payload. |
๐จ UI Customization (PitelCallConfig)โ
You can customize the appearance of the bundled SwiftUI PitelCallView by providing a custom PitelCallConfig:
let customConfig = PitelCallConfig(
colors: PitelCallConfig.Colors(
background: Color(red: 0.1, green: 0.1, blue: 0.12),
cardBackground: Color(red: 0.15, green: 0.15, blue: 0.18),
textPrimary: .white,
textSecondary: .gray,
buttonBackgroundActive: Color.green.opacity(0.2),
buttonBackgroundInactive: Color.white.opacity(0.1)
)
)
Config Properties Referenceโ
๐จ Colors (config.colors)โ
| Property | Description |
|---|---|
background | Main screen background color |
cardBackground | Action card background |
textPrimary | Caller name and primary title text color |
textSecondary | Subtitle / duration text color |
buttonBackgroundActive | Active highlight background for toggled buttons |
buttonBackgroundInactive | Default background for action buttons |
dialPadBackground | Keypad sheet background |
dialPadNumber | Keypad number text color |
๐ Texts (config.texts)โ
| Property | Default Value | Description |
|---|---|---|
outgoing | "Starting call..." | Outgoing call status text |
incoming | "Incoming..." | Incoming call status text |
mute / unmute | "Mute" / "Unmute" | Mute button label |
speaker | "Speaker" | Speaker audio route button label |
hold / unhold | "Hold" / "Unhold" | Hold button label |
transfer | "Transfer" | Transfer button label |
keypad | "Keypad" | Keypad button label |
endCall | "End Call" | End call button label |
โ FAQ & Troubleshootingโ
For complete QA testing scenarios and troubleshooting solutions, visit: