Self-handled cards give you the flexibility to create card campaigns on the MoEngage Platform and display the cards anywhere within the application. The SDK provides APIs to fetch the campaign’s data, which allows you to create your own custom view for the cards.Documentation Index
Fetch the complete documentation index at: https://moengage-sdk-docs.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
SDK Installation
Install using Swift Package Manager
MoEngageCards is supported through SPM from SDK version 3.2.0. To integrate use the following git hub url link and set the branch as master or version as 4.0.0 and above https://github.com/moengage/MoEngage-iOS-Cards.gitInstall using CocoaPod
InformationCocoaPods is being deprecated. MoEngage recommends using Swift Package Manager for all new integrations. For detailed info on cocoapods, refer to CocoaPods Integration Guide.
pod install to install the framework.
Manual Integration
Manual IntegrationTo integrate the
MoEngageCards SDK manually to your project follow this doc.Notify on Section Load
You can show the cards on a separate screen or a section of the screen. When the cards screen/section is loaded call onCardSectionLoaded()If you are using a
UIViewController as the cards page, call onCardSectionLoaded() inside viewWillAppear(_:) to ensure cards are synced each time the screen becomes visible.Fetch Categories
To fetch all the categories for which cards are configured use the API getCardsCategories(forAppID:withCompletionBlock:)Fetch Cards for Categories
To fetch cards eligible for display for a specific category use the API getCards(forCategory:forAppID:withCompletionBlock:)Track Statistics for Cards
Since the UI/display of the cards is controlled by the application to track statistics on delivery, display, click we need the application to notify the SDK.Delivered
To track delivery to the card section of the application use the API cardDelivered(_:forAppID:) when the cards section of the application is loaded by passing the instance of MoEngageCardCampaign.Impression
Call the method cardShown(_:forAppID:) when a specific card is visible on the screen.Click
Call the method cardClicked(_:withWidgetID:forAppID:) whenever a user clicks on a card, along with the card object widget identifier for the UI element clicked should also be passed.Delete Card
Call the method deleteCards(_:forAppID:andCompletionBlock:) to delete a card by passing an array of MoEngageCardCampaign as parameter.Fetch Cards from the Server
Use the fetchCards(forAppID:withCompletion:) API to refresh cards from the MoEngage server if required, MoEngageCardData is provided in callback with refreshed MoEngageCardCampaign in cards property and account meta-data MoEngageAccountMeta in accountMeta.NoteThe SDK caches cards and rate-limits server calls.
fetchCards() hit the server at most once every 5 minutes. If called more frequently, the existing cached cards are returned via the callback.FAQs
How do I handle near-real-time card updates (e.g., replacing a survey card after submission)?
How do I handle near-real-time card updates (e.g., replacing a survey card after submission)?
For use cases requiring immediate UI updates based on user actions, we recommend the following execution pattern:
- Initial Load: On screen load, call
fetchCards()to pull the latest cards from the server. - Trigger Update: After the user action (like a survey submission), call
onCardSectionLoaded(). This method returns ahasUpdatesflag in its completion handler. - Refresh UI: If
hasUpdatesis true, callgetCards(forCategory:)orgetCardsData()to retrieve the refreshed cards from local storage and update your view.
What is the difference between onCardSectionLoaded() and fetchCards()?
What is the difference between onCardSectionLoaded() and fetchCards()?
While both APIs involve fetching card data, they serve different purposes within the card lifecycle:
| Feature | onCardSectionLoaded() | fetchCards() |
|---|---|---|
| Use Case | Recommended for standard card inbox screens. | One-time force refresh outside the normal lifecycle. |
| Sync | Tracks impressions automatically. | Does not handle impression tracking. |
| Callback | Provides a hasUpdates flag in the completion handler. | Standard success/error completion. |