Quick Reference for AI Agents & Developers
- Requires: UNNotificationServiceExtension target in your app
- Remove specific:
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers:) - Remove all:
UNUserNotificationCenter.current().removeAllDeliveredNotifications() - Use case: Clear notifications when user reads message in-app
- Related: Push Notifications · Increment Badge Count
UNNotificationServiceExtension
This service grabs the data from the push notification payload, the user can modify its content and display the customized data on to the push notification. In our case, we are modifying the data of the push notification and incrementing the badge count when a new push notification is received. Let’s begin to implement an incremented badge count for your app.Step 1: Add UNNotificationServiceExtension inside the app.
- Click on
File—>New—>Targets—>Application Extension—>Notification Service Extension.

- Add
Product Nameand click onFinish.

Step 2: Add CometChat SDK in your Notification Extension.
Make sure you are adding the CometChat SDK in your Notification Extension. So in case if you are using pods then your pod file should contain the following:- Swift
Step 3: Add Code for removing Notifications.
Once you have successfully configured the Notification Service then add the below code indidReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) method under bestAttemptContent condition. The below code shows how you can remove the notifications for call type messages since we need to show the latest call notification.
- Swift
sessionID.
You can change the implementation as per your service. Once you added the code the above code add the completion handler in the main thread like shown below:
- Swift
Sample Payload - CometChat.processMessage() Input
Sample Payload - CometChat.processMessage() Input
Push Notification userInfo[“message”] Dictionary:
| Parameter | Type | Description |
|---|---|---|
| id | Int | Unique message identifier. Example: 12345 |
| category | String | Message category. Example: "call" |
| type | String | Call type. Example: "audio" |
| sessionId | String | Unique call session ID. Example: "call_session_abc123" |
| sender | String | Sender UID. Example: "john_doe" |
| receiver | String | Receiver UID. Example: "jane_smith" |
| receiverType | String | Receiver type. Example: "user" |
| status | String | Call status. Example: "initiated" |
| sentAt | Int | Unix timestamp. Example: 1699800000 |
Sample Payload - CometChat.processMessage() Output
Sample Payload - CometChat.processMessage() Output
Returns:
(BaseMessage?, CometChatException?)Call Object (when category is “call”):| Parameter | Type | Description |
|---|---|---|
| id | Int | Message ID. Example: 12345 |
| messageCategory | MessageCategory | Category. Example: .call |
| sessionID | String? | Call session ID. Example: "call_session_abc123" |
| callStatus | CallStatus | Status. Example: .initiated |
| callType | CallType | Type. Example: .audio |
| sender | User | Sender details. Example: User { uid: "john_doe" } |
Sample Payload - removeDeliveredNotifications
Sample Payload - removeDeliveredNotifications
UNNotification Object:
removeDeliveredNotifications Input:
Call Notification Flow:
| Parameter | Type | Description |
|---|---|---|
| request.identifier | String | Unique notification ID. Example: "notification_uuid_123" |
| request.content.title | String | Notification title. Example: "Incoming Call" |
| request.content.body | String | Notification body. Example: "John Doe is calling..." |
| request.content.userInfo | [AnyHashable: Any] | Push payload data |
| Parameter | Type | Description |
|---|---|---|
| identifiers | [String] | Array of notification IDs to remove. Example: ["notification_uuid_123"] |
| Step | Action | Description |
|---|---|---|
| 1 | Incoming call arrives | { sessionId: "abc123", status: "initiated" } |
| 2 | Call ends/unanswered | { sessionId: "abc123", status: "unanswered" } |
| 3 | Find matching notification | Match by sessionId |
| 4 | Remove old notification | Show only “Missed Call” |