With self handled cards we provide you the flexibility to build
Self-handled cards give you the flexibility of creating Card Campaigns on the MoEngage Platform and displaying the cards anywhere inside the application. SDK provides APIs to fetch the campaign's data using which you can create your own view for cards.
SDK Installation
Install using CocoaPod
Integrate the MoEngageCards framework by adding the dependency in the podfile as shown below.
pod 'MoEngageCards','~> 3.2.0'
Now run pod install
to install the framework
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 3.2.0 and above https://github.com/moengage/MoEngage-iOS-Cards.git
Manual Integration
info |
Manual Integration To integrate the |
Use the below APIs to fetch the card's data and build your own UI.
Fetch Categories
To fetch all the categories for which cards are configured use the below API.
MOCards.sharedInstance.getCardsCategories { categories, account in
print("Fetched Cards Categories \(categories)")
}
[[MOCards sharedInstance] getCardsCategoriesForAppID:@"YOUR Workspace ID" withCompletionBlock:^(NSArray * _Nonnull categories, MOAccountMeta * _Nullable accountMeta) {
NSLog(@"Fetched Cards Categories");
}];
Fetch Cards for Categories
To fetch cards eligible for display for a specific category use the below API
MOCards.sharedInstance.getCards(forCategory: "CATEGORY") { cards, accountMeta in
print("Fetched cards for given category")
}
[[MOCards sharedInstance] getCardsForCategory:@"CATEGORY" forAppID:@"YOUR Workspace ID" withCompletionBlock:^(NSArray * _Nonnull cardCamapigns, MOAccountMeta * _Nullable accountMeta) {
NSLog(@"Fetched cards for given category");
}];
Instead of using separate APIs to fetch the Cards and categories you can use the below API to fetch all the information in one go
MOCards.sharedInstance.getCardsData() { cardsData, accountMeta in
print("Cards category \(cardsData?.cardCategories)")
print("Cards Data \(cardsData?.cards)")
// To get the cards clicked state use cardState object
print("Card clicked \(cardsData?.cards[0].cardState.isClicked)")
}
[[MOCards sharedInstance] getCardsDataForAppID:@"YOUR Workspace ID" withCompletionBlock:^(MOCardsData * _Nullable cardsData, MOAccountMeta * _Nullable accountMeta) {
NSLog(@"Cards category %@", cardsData.cardCategories);
NSLog(@"Cards Data %@", cardsData.cards);
NSLog(@"Cards Data %@", cardsData.cards[0].cardState.isClicked);
}];
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 call the below API when the cards section of the application is loaded by passing the instance of MOCardCampaign
MOCards.sharedInstance.cardDelivered(cardCampaign)
[[MOCards sharedInstance] cardDelivered:cardCamapigns forAppID:@"YOUR Workspace ID"];
Impression
Call the below API when a specific card is visible on the screen.
MOCards.sharedInstance.cardShown(cardCampaign)
[[MOCards sharedInstance] cardShown:cardCamapign forAppID:@"YOUR Workspace ID"];
Click
Call the below API whenever a user clicks on a card, along with the card object widget identifier for the UI element clicked should also be passed.
MOCards.sharedInstance.cardClicked(cardCampaign, withWidgetID: widgetID);
[[MOCards sharedInstance] cardClicked:cardCamapigns withWidgetID:widgetID forAppID:@"YOUR Workspace ID"];
Delete Card
Call the below API to delete a card by passing an array of MOCardCampaign as parameter
MOCards.sharedInstance.deleteCards([cards]) { isDeleted, accountMeta in
print("Card deletion was \(isDeleted)")
}
[[MOCards sharedInstance] deleteCards:[cardCamapigns] forAppID:nil andCompletionBlock:^(BOOL isDeleted, MOAccountMeta * _Nullable accountMeta) {
NSLog(@"Card deletion was %d", isDeleted);
}];
The above API has an overloaded method that accepts a list of cards to be deleted.