Skip to main content

๐ŸŽ 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.

IMPORTANT
  • 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 .p12 file to the Pitel SDK Portal periodically every year to avoid VoIP push notification disruptions.

๐Ÿ“š Documentation Indexโ€‹

GuideDescription
๐Ÿš€ Quick Start Guide3-step plug & play integration with native Apple CallKit.
๐Ÿ iOS VoIP Push & CallKit SetupNative iOS configuration, PushKit APNs certificates, and AppDelegate setup.
๐ŸŒ Pitel Portal Setup GuideStep-by-step guide to register Bundle ID, Team ID, and upload .p12 certificates.
๐Ÿ“ฑ Sample Demo ProjectFully runnable iOS SwiftUI sample project with PushKit, CallKit, and in-call UI.
๐Ÿ“– SIP Disconnect Codes ReferenceComprehensive SIP status code lookup table (486 Busy, 408 Timeout, 603 Decline...).
โ“ FAQ & 10 QA Test Cases Checklist10 real-world test scenarios for QA/Dev & solutions to common iOS CallKit pitfalls.
๐Ÿ› ๏ธ Troubleshooting GuideDetailed 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)โ€‹

  1. In Xcode, select File โ†’ Add Package Dependencies...
  2. Enter the official distribution repository URL:
    https://github.com/voip-sdk/ios-pitel-voip-sdk.git
  3. 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:

  1. In Xcode, select File โ†’ Add Package Dependencies...
  2. Enter the official Firebase iOS SDK repository URL:
    https://github.com/firebase/firebase-ios-sdk.git
  3. Add the following libraries to your target:
    • โœ… FirebaseCore
    • โœ… FirebaseMessaging
  4. Download your GoogleService-Info.plist from 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โ€‹

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)")
}
}
NOTE

When PitelVoIP.makeCall() is executed:

  1. Microphone permission is automatically requested if not yet granted.
  2. Native Apple CallKit registers the outgoing session.
  3. The built-in in-call screen (PitelCallView) is automatically presented over your active window (configured in Step 2 via registerCallPresentationHostProvider). 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)โ€‹

NOTE

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:

MethodParametersDescription
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, sipInfoUnregisters 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()NoneTerminates active call immediately.
PitelVoIP.mute()NoneMutes microphone.
PitelVoIP.unmute()NoneUnmutes microphone.
PitelVoIP.hold()NoneHolds current call.
PitelVoIP.unhold()NoneResumes held call.
PitelVoIP.sendDTMF(_:)String (0-9, *, #)Sends DTMF tones during active call.
PitelVoIP.transferCall(to:)to: StringBlind 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)โ€‹

PropertyDescription
backgroundMain screen background color
cardBackgroundAction card background
textPrimaryCaller name and primary title text color
textSecondarySubtitle / duration text color
buttonBackgroundActiveActive highlight background for toggled buttons
buttonBackgroundInactiveDefault background for action buttons
dialPadBackgroundKeypad sheet background
dialPadNumberKeypad number text color

๐Ÿ“ Texts (config.texts)โ€‹

PropertyDefault ValueDescription
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: