Before using the SDK, set up your channels, categories, templates, and campaigns in the CometChat Dashboard. See the Dashboard Setup Guide for step-by-step instructions.
Card Messages
A Card Message is a structured, interactive message rendered as a card bubble inside a conversation. Cards are receive-only on the SDK: they are created through the Platform REST API or the Dashboard Bubble Builder and delivered to clients like any other message — the SDK does not send them.- Type:
CardMessage(CometChatSDK) - Category:
"card"(MessageCategory.card)
Properties
Listening for card messages
To be notified when a card message arrives, implementonCardMessageReceived on your CometChatMessageDelegate.
- Swift
CometChatMessageDelegate reference.
CometChatCardsSwift
CometChatCardsSwift is the rendering library for Campaigns. The NotificationFeedItem.content field contains a Card Schema JSON — a structured layout definition. CometChatCardsSwift takes this JSON and produces a native UIKit view. Without it, content is just a raw dictionary.
The library:
- Parses the JSON schema into typed Swift models.
- Renders native UIKit views (no web views) for each element (text, images, buttons, rows, etc.).
- Handles light/dark mode color resolution from themed color pairs.
- Manages interactive actions — button taps emit structured
CometChatCardActionEventobjects with the action type and element ID. - Supports dynamic content — accordions expand/collapse, tabs switch panels, all with proper auto-layout height changes.
CometChatNotificationFeed (UI Kit), the Cards library is used internally and you don’t interact with it directly. If you’re building a custom feed UI, you import CometChatCardsSwift and use CometChatCardView to render each item’s content.
Setting Up CometChatCardsSwift
Installation
Swift Package Manager In Xcode: File → Add Package Dependencies → enter:CometChatCardsSwift to your target.
CocoaPods
Rendering Feed Items as Cards
CometChatCardView Properties
Theme Override
Override default card theme colors to match your app’s brand:Content Size Changes
Cards with expandable content (accordions, tabs) change height dynamically. Observe size changes to update your layout:Key Concepts
How Cards Render in the Notification Feed
EachNotificationFeedItem has a content field containing a [String: Any] dictionary — this is the Card Schema JSON. This JSON is passed directly to the CometChat Cards renderer library.
The rendering flow:
- Fetch feed items via
NotificationFeedRequest - For each item, extract
item.content— this is the Card Schema JSON - Pass to the Cards renderer (
CometChatCardView) - The renderer produces a native UIKit view from the JSON
Card Schema JSON Structure
body array contains elements (text, image, button, row, column, etc.) rendered top-to-bottom. Interactive elements like buttons emit actions via a callback — the consumer handles navigation, deep links, or API calls.
Retrieve Notification Feed Items
UseNotificationFeedRequest to fetch a paginated list of feed items. Uses cursor-based pagination internally.
Build the Request
Builder Parameters
set(category:) and set(categoryId:) both map to the same server-side filter (templateCategory). Use one or the other — not both. If both are provided, categoryId silently overwrites category.Fetch Items
fetchNext() repeatedly for pagination. When the server has no more items, subsequent calls return an empty array.
NotificationFeedItem Fields
Retrieve Notification Categories
UseNotificationCategoriesRequest to fetch available categories for filter chips.
NotificationCategory Fields
Real-Time Notification Feed Listener
Listen for new feed items arriving via WebSocket. This listener is independent fromCometChatMessageDelegate, CometChatGroupDelegate, and CometChatCallDelegate.
Mark Feed Item as Read
Mark a single item as read. Idempotent — safe to call multiple times.Mark Feed Item as Delivered
Mark a single item as delivered. Idempotent.Report Engagement
Report that a user engaged with a feed item (e.g., viewed, clicked, interacted). Idempotent per topic.interactionString parameter is a free-form string describing the engagement (e.g., “viewed”, “clicked”, “interacted”).
Get Unread Count
Fetch the total number of unread notification feed items. Optionally filter by category.Fetch Single Feed Item
Fetch a specific item by ID — useful for deep linking from push notifications.Push Notification Tracking
When a campaign push notification arrives via APNs, use these methods to report delivery and click engagement.Setting Up Notification Service Extension
- In Xcode: File → New → Target → select Notification Service Extension.
- Enable App Groups on both your main app target and the extension target with the same group ID (e.g.,
group.com.yourapp.cometchat). - Add
CometChatSDKas a dependency to the extension target.
Identifying Campaign Push Notifications
Campaign pushes contain acometchat dictionary with "type": "business_messaging":
Push Payload Structure
Mark Push Notification as Delivered
Call this in your Notification Service Extension:Mark Push Notification as Clicked
Call this when the user taps the push notification:PushNotification Fields
FeedReadState Enum
If not set, returns all items (default).