Skip to main content
CometChat Campaigns lets you deliver targeted, rich notifications to users via an in-app notification feed. Each notification is a Card Schema JSON — a structured layout rendered natively by the CometChat Cards library. The SDK provides APIs to fetch feed items, listen for real-time delivery, mark items as read/delivered, report engagement, and retrieve unread counts.
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, implement onCardMessageReceived on your CometChatMessageDelegate.
See Message Delegate Methods for the full 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 CometChatCardActionEvent objects with the action type and element ID.
  • Supports dynamic content — accordions expand/collapse, tabs switch panels, all with proper auto-layout height changes.
If you use 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:
Add CometChatCardsSwift to your target. CocoaPods
No initialization is required. The library is stateless — import it and start rendering.

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

Each NotificationFeedItem 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:
  1. Fetch feed items via NotificationFeedRequest
  2. For each item, extract item.content — this is the Card Schema JSON
  3. Pass to the Cards renderer (CometChatCardView)
  4. The renderer produces a native UIKit view from the JSON

Card Schema JSON Structure

The 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

Use NotificationFeedRequest 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

Call fetchNext() repeatedly for pagination. When the server has no more items, subsequent calls return an empty array.

NotificationFeedItem Fields


Retrieve Notification Categories

Use NotificationCategoriesRequest 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 from CometChatMessageDelegate, CometChatGroupDelegate, and CometChatCallDelegate.
Remove the listener when no longer needed:

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.
The 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

  1. In Xcode: File → New → Target → select Notification Service Extension.
  2. Enable App Groups on both your main app target and the extension target with the same group ID (e.g., group.com.yourapp.cometchat).
  3. Add CometChatSDK as a dependency to the extension target.

Identifying Campaign Push Notifications

Campaign pushes contain a cometchat 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).

Supported Card Actions

When a user taps a button or link inside a card, the action callback receives one of these action types: