Skip to main content

React Native UI Kit Sample App

Reference implementation of React Native UI Kit and APNs Push Notification setup.

What this guide covers

  • CometChat Dashboard setup (enable push, add APNs provider).
  • Platform credentials (Apple entitlements).
  • Copying the sample notification stack and aligning IDs/provider IDs.
  • Native glue for iOS (capabilities + PushKit/CallKit for VoIP).
  • Token registration, navigation from pushes, testing, and troubleshooting.

What you need first

  • CometChat app credentials (App ID, Region, Auth Key) and Push Notifications enabled with an APNs provider (React Native iOS); add an APNs VoIP provider if you plan to receive call invites via PushKit.
  • Apple push setup: APNs .p8 key/cert in CometChat, iOS project with Push Notifications + Background Modes (Remote notifications) permissions.
  • React Native 0.81+, Node 18+, physical iOS device for reliable push/call testing.

How APNs + CometChat work together

  • APNs (iOS) is the transport: Apple issues the APNs token and delivers payloads to devices.
  • CometChat provider holds your credentials: The APNs provider you add stores your .p8 key/cert.
  • Registration flow: Request permission → APNs returns token → after CometChat.login, register with CometChatNotifications.registerPushToken(token, platform, providerId) using APNS_REACT_NATIVE_DEVICE → CometChat sends pushes to APNs on your behalf → the app handles taps/foreground events via PushNotificationIOS.

1. Enable push and add providers (CometChat Dashboard)

  1. Go to Notifications → Settings and enable Push Notifications.
Enable Push Notifications
  1. Add an APNs provider for iOS and copy the Provider ID.
Upload APNs credentials

2. Prepare platform credentials

Apple Developer portal

For iOS we use Apple Push Notification service (APNs) for both standard and VoIP pushes. Follow these steps to create the credentials you’ll upload to CometChat.
1

Create a certificate signing request (CSR)

  1. Open Keychain Access → Certificate Assistant → Request a Certificate From a Certificate Authority.
Apple Developer portal screenshot
  1. In Certificate Information, enter your Apple Developer email and a common name; choose Saved to disk, then Continue.
  2. Save the CSR file locally—this contains your public/private key pair.
2

Create the APNs SSL certificate (.cer)

  1. Sign in to the Apple Developer Member CenterCertificates, Identifiers & Profiles.
Apple Developer portal screenshot
  1. Click + to add a certificate.
Apple Developer portal screenshot
  1. Under Services, pick Apple Push Notification service SSL (Sandbox & Production).
Apple Developer portal screenshot
  1. Select your App ID, upload the CSR, continue, and download the generated .cer file.
Apple Developer portal screenshot
&
Apple Developer portal screenshot
&
Apple Developer portal screenshot
3

Generate the APNs Auth Key (.p8)

  1. In Certificates, IDs & Profiles, open Keys → click +.
  2. Enter a key name, check Apple Push Notification service (APNs), then ContinueRegister.
  3. Download the .p8 file and note the Key ID, Team ID, and your Bundle ID—you’ll enter these in CometChat.
  4. (Optional) If you still use .p12, export it from the downloaded key without an export password; keep it handy for upload.
.p12 certificates are deprecated. Apple recommends using .p8 Auth Keys for push notifications. .p8 keys are simpler to manage (one key works for all your apps), never expire, and are the only format actively supported going forward. Migrate to .p8 if you haven’t already.
Enable Push Notifications plus Background Modes → Remote notifications on the bundle ID.
Enable Push Notifications and Background Modes for APNs

3. Local configuration

  • Update src/utils/AppConstants.tsx with appId, authKey, region, and apnProviderId.
  • Keep app.json name consistent with your bundle ID / applicationId.

3.1 Dependencies snapshot (from Sample App)

Install these dependencies in your React Native app:
Match these or newer compatible versions in your app.

4. iOS App setup

4.1 Project Setup

Enable Push Notifications and Background Modes (Remote notifications) in Xcode.
Enable Push Notifications

4.2 Install dependencies + pods

After running the npm install above, install pods from the ios directory:

4.3 AppDelegate.swift modifications:

Add imports at the top:
Add UNUserNotificationCenterDelegate to the AppDelegate class declaration:
Add the following inside the didFinishLaunchingWithOptions method:
Add the following methods to handle push notification events:
Add the following to Podfile to avoid framework linkage issues:
You might have to remove below code if already present in your Podfile:
Then lets install pods and open the workspace:

4.4 App.tsx modifications:

Import CometChatNotifications and PushNotificationIOS:
Get device token and store it in a ref: Also, define your APNs provider ID from the CometChat Dashboard. And request permissions on mount:
After user login, register the APNs token:
Prior to logout, unregister the APNs token:

5. VoIP call notifications (iOS)

These steps are iOS-only—copy/paste and fill your IDs.

5.1 Enable capabilities in Xcode

  • Target ➜ Signing & Capabilities: add Push Notifications.
  • Add Background Modes → enable Voice over IP and Remote notifications.
  • Run on a real device (PushKit/CallKit don’t work on the simulator).

5.2 AppDelegate.swift (PushKit + CallKit bridge)

Update your AppDelegate to register for VoIP pushes ASAP and forward events to JS/CallKeep:

5.3 Drop in VoipNotificationHandler.ts

Handles CallKeep UI, defers acceptance until login, and listens for PushKit events.

5.4 Add PendingCallManager.ts

Stores an answered call during cold start so you can accept it after login/navigation is ready.

5.5 Wire App.tsx for APNs + VoIP token registration and handler init

5.6 VoIP push payload (APNs / PushKit)

Send a VoIP push with push_type=voip via APNs using a payload shaped like:

6. Handling notification taps and navigation

To handle notification taps and navigate to the appropriate chat screen, you need to set up handlers for both foreground and background notifications.

7. Badge Count Implementation

CometChat’s Enhanced Push Notification payload includes an unreadMessageCount field that represents the total number of unread messages across all conversations for the logged-in user. You can use this value to update the app icon badge, providing users with a visual indicator of unread messages.

7.1 Enable Unread Badge Count on the CometChat Dashboard

1

Navigate to Push Notification Preferences

Go to CometChat Dashboard → Notifications Engine → Settings → Preferences → Push Notification Preferences.
2

Enable the Toggle

Scroll down and enable the Unread Badge Count toggle.
Once enabled, CometChat automatically includes the unreadMessageCount field in every push payload sent to your app.

7.2 Expected Payload Format

CometChat sends APNs payloads with the following structure:
The aps.badge field is set server-side by CometChat. iOS automatically updates the app icon badge when the push notification is delivered.

7.3 Handle Badge Count from Notifications

Update your iOS notification handler to set the badge count programmatically:

7.4 Register Notification Listener

In your App.tsx, set up the notification listener:

7.5 Clear Badge When App Becomes Active

Clear the badge count when the app launches or returns to the foreground:

7.6 Clear Badge on Logout

When a user logs out, clear the badge so it doesn’t show a stale count on the login screen or for the next user:

7.7 Clear Badge on Fresh Install / No Logged-In User

On iOS, the badge count may persist after app uninstall and reinstall in certain scenarios. Clear the badge during app initialization when no user is logged in:

7.8 Clear Badge in Login Listener (Safety Net)

Register a login listener to clear the badge on logout as a backup mechanism:

7.9 Key Implementation Notes

7.10 Cross-Platform App State Handler

If you’re building a cross-platform app, use this combined handler for both iOS and Android:

8. Testing Checklist

  1. Install on a physical iOS device, log in, and verify APNs token registration succeeds.
  2. Send a message from another user:
    • Foreground: Banner appears unless that chat is already open.
    • Background/terminated: Tap opens the correct conversation; handler runs.
  3. VoIP: Send a PushKit VoIP push (payload above); expect CallKit incoming UI; answer and confirm CometChat call connects; end clears the dialer.
  4. Rotate tokens (reinstall or revoke) and confirm onTokenRefresh re-registers the new token.

9. Troubleshooting


Next Steps

Push Notifications (Android)

Set up FCM push notifications for Android

Push Notification Content Customization

Strip HTML tags and customize notification content

Send Messages

Learn how to send different types of messages

Receive Messages

Handle incoming messages in real time