API Reference
This document lists the public APIs available in the Messaging extension for implementing content card with UI.
getContentCardsUI
The getContentCardsUI method retrieves an array of ContentCardUI objects for the provided surface. These ContentCardUI objects provide the user interface for templated content cards to your application.
Parameters
-
surface - The Surface for which the content cards should be retrieved.
-
customizer - An optional ContentCardCustomizing object to customize the appearance of the content card template. If you do not need to customize the appearance of the content card template, this parameter can be omitted.
-
listener - An optional ContentCardUIEventListening object to listen to UI events from the content card. If you do not need to listen to UI events from the content card, this parameter can be omitted.
-
completion - A completion handler that is called with a
Resultcontaining either:- success - An array of ContentCardUI objects representing the content cards to be displayed.
- failure - An
Errorobject indicating the reason for the failure, if any.
data-variant=info
data-slots=text
updatePropositionsForSurfaces API with the desired surfaces prior to calling this API.Syntax
data-slots=heading, code
data-repeat=1
Swift
public static func getContentCardsUI(for surface: Surface,
customizer: ContentCardCustomizing? = nil,
listener: ContentCardUIEventListening? = nil,
_ completion: @escaping (Result<[ContentCardUI], Error>) -> Void)
Example
data-slots=heading, code
data-repeat=1
Swift
// Download the content cards for homepage surface using Messaging extension
let homePageSurface = Surface(path: "homepage")
Messaging.updatePropositionsForSurfaces([homePageSurface])
// Get the content card UI for the homepage surface
Messaging.getContentCardsUI(for: homePageSurface) { result in
switch result {
case .success(let contentCards):
// Use the contentCards array to display UI for templated content cards in your application
case .failure(let error):
// Handle the error
}
}