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.
SDK Installation
Install using CocoaPod
Integrate the MoEngageCards framework by adding the dependency in the podfile as shown below.
pod 'MoEngage-iOS-SDK/Cards','~> 9.18.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 4.0.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 API getCardsCategories(forAppID:withCompletionBlock:)
MoEngageSDKCards.sharedInstance.getCardsCategories { categories, accountMeta in
print("Fetched Cards Categories \(categories)")
}
[[MoEngageSDKCards sharedInstance] getCardsCategoriesForAppID:@"Your Workspace Id" withCompletionBlock:^(NSArray * _Nonnull, MoEngageAccountMeta * _Nullable) {
NSLog(@"Fetched Cards Categories");
}];
Fetch Cards for Categories
To fetch cards eligible for display for a specific category use the API getCards(forCategory:forAppID:withCompletionBlock:)
MoEngageSDKCards.sharedInstance.getCards(forCategory: "CATEGORY") { cards, accountMeta in
print("Fetched cards for given category")
}
[[MoEngageSDKCards sharedInstance] getCardsForCategory:@"CATEGORY" forAppID:@"YOUR Workspace ID" withCompletionBlock:^(NSArray * _Nonnull, MoEngageAccountMeta * _Nullable) {
NSLog(@"Fetched cards for given category");
}];
Instead of using separate APIs to fetch the Cards and categories you can use the method getCardsData(forAppID:withCompletionBlock:) to fetch all the information in one go
MoEngageSDKCards.sharedInstance.getCardsData { cardsData, accountMeta in
print("Cards category \(cardsData?.cardCategories)")
print("Cards Data \(cardsData?.cards)")
}
[[MoEngageSDKCards sharedInstance] getCardsDataForAppID:@"YOUR Workspace ID" withCompletionBlock:^(MoEngageCardsData * _Nullable, MoEngageAccountMeta * _Nullable) {
NSLog(@"Cards category %@", cardsData.cardCategories);
NSLog(@"Cards Data %@", cardsData.cards);
}];
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
MoEngageSDKCards.sharedInstance.cardDelivered(cardCampaign, forAppID: "YOUR Workspace ID")
[[MoEngageSDKCards sharedInstance] cardDelivered:cardCamapigns forAppID:@"YOUR Workspace ID"];
Impression
Call the method cardShown(_:forAppID:) when a specific card is visible on the screen.
MoEngageSDKCards.sharedInstance.cardShown(cardCampaign, forAppID: "YOUR Workspace ID")
[[MoEngageSDKCards sharedInstance] cardShown:cardCamapign forAppID:@"YOUR Workspace ID"];
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.
MoEngageSDKCards.sharedInstance.cardClicked(cardCampaign, withWidgetID: widgetID);
[[MoEngageSDKCards sharedInstance] cardClicked:cardCamapigns withWidgetID:widgetID forAppID:@"YOUR Workspace ID"];
Delete Card
Call the method deleteCards(_:forAppID:andCompletionBlock:) to delete a card by passing an array of MoEngageCardCampaign as parameter
MoEngageSDKCards.sharedInstance.deleteCards([cards]) { isDeleted, accountMeta in
print("Card deletion was \(isDeleted)")
}
[[MoEngageSDKCards sharedInstance] deleteCards:[cardCamapigns] forAppID:nil andCompletionBlock:^(BOOL isDeleted, MoEngageAccountMeta * _Nullable accountMeta) {
NSLog(@"Card deletion was %d", isDeleted);
}];
The above API has an overloaded method that accepts a list of cards to be deleted.
Refresh 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.
MoEngageSDKCards.sharedInstance.fetchCards { data in
print("Refreshed cards: \(data?.cards) for account \(data?.accountMeta)")
}
[[MoEngageSDKCards sharedInstance] fetchCardsForAppID:nil withCompletion:^(MoEngageCardData * _Nullable data) {
NSLog(@"Refreshed cards: %@ for account %@", data.cards, data.accountMeta);
}];
info |
Note
|