InboxEventListening
A protocol that defines methods for listening to state changes and content card interaction events from an InboxUI instance.
Protocol Definition
Copied to your clipboardpublic protocol InboxEventListening {func onLoading(_ inbox: InboxUI)func onSuccess(_ inbox: InboxUI)func onError(_ inbox: InboxUI, _ error: Error)func onCardCreated(_ card: ContentCardUI)func onCardDisplayed(_ card: ContentCardUI)func onCardDismissed(_ card: ContentCardUI)func onCardInteracted(_ card: ContentCardUI, _ interactionId: String, actionURL: URL?) -> Bool}
All methods have default no-op implementations, so you only need to implement the methods relevant to your use case.
Inbox State Methods
onLoading
Called when the inbox begins loading content. Triggered when the InboxUI is first created or when a refresh (pull-to-refresh or programmatic) begins.
Parameters
- inbox - The InboxUI that is loading.
Syntax
Copied to your clipboardfunc onLoading(_ inbox: InboxUI)
onSuccess
Called when the inbox successfully loads content. Triggered whether the inbox contains cards or is empty.
Parameters
- inbox - The InboxUI that loaded successfully.
Syntax
Copied to your clipboardfunc onSuccess(_ inbox: InboxUI)
onError
Called when the inbox encounters an error while loading. See InboxError for the error types that can be returned.
Parameters
- inbox - The InboxUI that encountered an error.
- error - The error describing what went wrong.
Syntax
Copied to your clipboardfunc onError(_ inbox: InboxUI, _ error: Error)
Content Card Methods
onCardCreated
Called when a content card is created and configured. This is called once per card when the inbox loads or refreshes.
Parameters
- card - The
ContentCardUIthat was created.
Syntax
Copied to your clipboardfunc onCardCreated(_ card: ContentCardUI)
onCardDisplayed
Called when a content card appears on screen. Use this to track card impressions.
Parameters
- card - The
ContentCardUIthat was displayed.
Syntax
Copied to your clipboardfunc onCardDisplayed(_ card: ContentCardUI)
onCardDismissed
Called when a user dismisses a content card. The inbox automatically removes the dismissed card from the UI.
Parameters
- card - The
ContentCardUIthat was dismissed.
Syntax
Copied to your clipboardfunc onCardDismissed(_ card: ContentCardUI)
onCardInteracted
Called when the user interacts with a content card (e.g., taps a button or link). The return value controls whether the SDK handles the actionURL.
Parameters
- card - The
ContentCardUIthat was interacted with. - interactionId - A string identifier for the interaction (e.g., a button ID).
- actionURL - The optional URL associated with the interaction.
Returns
Return true if your application handled the actionURL. Return false to let the SDK handle it.
Syntax
Copied to your clipboardfunc onCardInteracted(_ card: ContentCardUI, _ interactionId: String, actionURL: URL?) -> Bool
Example
Copied to your clipboardfunc onCardInteracted(_ card: ContentCardUI, _ interactionId: String, actionURL: URL?) -> Bool {guard let url = actionURL else { return false }if url.scheme == "myapp" {handleDeepLink(url)return true // app handled it}return false // let SDK open the URL}
