This is the recommended way to add push notifications and VoIP calling to an iOS app.
CometChatPushNotifications handles APNs and PushKit token registration, foreground
presentation, notification taps, quick reply, campaign receipts, badge counts and the whole
PushKit + CallKit incoming-call flow. You do not write a PKPushRegistry or a
CXProviderDelegate.It works with or without the UI Kit. If you would rather wire APNs, PushKit and CallKit
yourself, see iOS APNs Push Notifications.Requirements
Install
- Swift Package Manager
- CocoaPods
In Xcode, File → Add Package Dependencies and add:Pick version 1.0.0 or later, and add the
CometChatPushNotificationsSwift library to your
app target.Before you start
- In the CometChat dashboard, enable Push Notifications and add your APNs credentials. Add an APNs Device provider and an APNs VoIP provider, and copy the Provider ID.
- In Xcode, add these capabilities to your app target:
- Push Notifications
- Background Modes → Voice over IP and Remote notifications
- Add
NSMicrophoneUsageDescriptionandNSCameraUsageDescriptionto yourInfo.plist— iOS terminates the app at the first call permission request without them.
1. Initialize
Call this afterCometChat.init(...):
UNUserNotificationCenter handling.
You do not call
CometChatNotifications.registerPushToken(...) yourself. The SDK does it on
every login, for both the APNs device token and the PushKit VoIP token.2. Forward the APNs token
In yourAppDelegate:
registerDeviceToken takes optional onSuccess / onError closures if you want the result.
The token can arrive before
initialize(config:) runs. The SDK caches it and registers it
automatically once you initialize and the user logs in, so ordering is not your problem.AppDelegate code required. There is no PKPushRegistryDelegate and no
CXProviderDelegate to write.
3. Implement the delegate
Every method has a default no-op implementation — override only what you need.Cold start: tell the SDK when the Calls SDK is ready
A VoIP push can wake your app before your Calls SDK is ready. The SDK buffers thepresentCallScreen callback until you tell it to release.
Call notifyCallsSDKReady() once login has resolved — not merely when init succeeds:
There is a 3-second safety timeout: if
notifyCallsSDKReady() has not been called by then,
the SDK fires the buffered presentCallScreen anyway so the call is never silently dropped. A
cold start whose login takes longer than 3 seconds will therefore reach presentCallScreen
before login completes — handle that in your call screen rather than assuming a live session.Notification Service Extension
Adds delivery receipts, sender avatars, campaign images and markdown-free notification text.1
Add the target
File → New → Target → Notification Service Extension.
2
Share an App Group
Add the same App Group (e.g.
group.com.yourcompany.yourapp) to both the app target and the
extension target, and pass it as extensionGroupID when you initialize.3
Subclass the base class
Link
CometChatPushNotificationsSwift to the extension target and replace the generated class:4
Point the extension at the App Group
Add a String entry
CometChatExtensionGroupID set to your App Group ID in the extension’s
Info.plist, or override the extensionGroupID property instead.stripsMarkdown, attachesMedia, and finalizeContent(_:) for last-chance
content customization.
Configuration reference
foregroundCallPresentation decides what happens when a call arrives while the app is open:
Other APIs
Testing checklist
- Run on a physical device — VoIP pushes never reach the Simulator.
- Confirm both providers exist in the dashboard and that
providerIdmatches the one you passed. - Watch
onPushTokenRegistrationFailed— a wrong Provider ID shows up here first. - Test an incoming call in all three states: foreground, background, and app terminated
(cold start — this is what
notifyCallsSDKReady()covers).
Related
Push Notifications Overview
Dashboard setup, providers and templates.
Manual APNs + CallKit integration
The hand-wired alternative, if you need full control over PushKit and CallKit.
Calls: ringing
The in-app 1:1 call signaling this builds on.