Skip to main content

iOS UI Kit Sample App

Reference implementation of iOS UIKit, APNs and Push Notification Setup.

What this guide covers

  • CometChat dashboard setup (enable push, add APNs Device + APNs VoIP providers) with screenshots.
  • APNs + PushKit/CallKit wiring (tokens, delegates, CallKit).
  • Incoming message/call handling and deep links.
  • Payload customization and testing.

How APNs + CometChat work together

  • APNs is the transport: Apple issues the APNs device/VoIP tokens and delivers the payloads. No FCM bridge is involved.
  • CometChat providers: The APNs Device and APNs VoIP providers you add in the CometChat dashboard hold your APNs key/cert. When you call CometChatNotifications.registerPushToken(..., .APNS_IOS_DEVICE / .APNS_IOS_VOIP, providerId) after login, CometChat binds those tokens to the logged-in user and sends to APNs for you.
  • Flow: Permission prompt → APNs returns device + VoIP tokens → after CometChat.login, register both tokens with the matching provider IDs → CometChat sends to APNs → APNs delivers → UNUserNotificationCenterDelegate (and PushKit/CallKit for VoIP) surface the notification/tap.

1. Enable push and add providers (CometChat Dashboard)

  1. Go to Notifications → Settings and enable Push Notifications.
Enable Push Notifications
  1. Click Add Credentials:
    • Add an APNs Device provider (alerts) using your .p8 key, Team ID, Key ID, and Bundle ID; copy the Provider ID.
    • Add an APNs VoIP provider (calls) with the same .p8 (recommended for CallKit reliability); copy the Provider ID.
Add APNs credentials
Keep the provider IDs—you’ll paste them into your app constants.

2. Apple setup

  1. Capabilities: Push Notifications, Background Modes → Remote notifications & Voice over IP, CallKit usage descriptions in Info.plist (mic/camera).
  2. APNs Auth Key: generate .p8 (or use cert), note Key ID, Team ID, and Bundle ID; upload to CometChat providers.
Enable Push Notifications and Background Modes for APNs

3. Wiring APNs + PushKit/CallKit

  • From below code, copy CometChatAPNsHelper.swift, CometChatPNHelper.swift, and the two AppDelegate extensions (AppDelegate+PN.swift and AppDelegate+VoIP.swift) into your project.
  • These files implement APNs + PushKit/CallKit handling, notification presentation, tap and quick-reply actions, and call management.
  • Update bundle ID, team ID, and provider IDs (AppConstants.PROVIDER_ID etc.). Keep the voip push type.

4. Register APNs device + VoIP tokens with CometChat

  • In your AppDelegate.swift, implement the following methods to handle APNs registration success and failure, and to register the device token with CometChat.
  • Make sure to import the necessary modules at the top of the file.
  • Complete your AppDelegate.swift as shown below:

5. Testing checklist

  1. Install on a device; grant notification permission. Verify APNs device token logs.
  2. Log in, then confirm both device + VoIP tokens register with CometChat (success callbacks).
  3. Send a message from another user:
    • Foreground: ensure willPresent shows your chosen presentation.
    • Background/terminated: tapping opens the correct conversation.
  4. Trigger an incoming call; CallKit UI should show caller info. Accept should join the call; Decline should reject via CometChat and end CallKit.
  5. Rotate tokens (reinstall or toggle VoIP) to ensure re-registration works.

6. Troubleshooting