Fetch and Display Inbox
This tutorial explains how to fetch and display an Inbox in your application.
Pre-requisites
Integrate and register the AEPMessaging extension in your app.
Fetch Inbox Content
To fetch the inbox content for the surfaces configured in Adobe Journey Optimizer campaigns, call the updatePropositionsForSurfaces API. You should batch requests for multiple surfaces in a single API call when possible.
Copied to your clipboardlet inboxSurface = Surface(path: "inbox")Messaging.updatePropositionsForSurfaces([inboxSurface])
Display Inbox
To display an Inbox, call getInboxUI with your configured surface. This API returns an InboxUI instance immediately, which manages its own state transitions — loading, loaded, and error — automatically.
Call updatePropositionsForSurfaces before or after calling getInboxUI. The Inbox will begin displaying content once the fetch completes.
SwiftUI Application
Use the InboxUI.view property to embed the Inbox directly into your SwiftUI view hierarchy.
Copied to your clipboardimport SwiftUIimport AEPMessagingstruct InboxPage: View {let inboxUI: InboxUIinit() {let inboxSurface = Surface(path: "inbox")inboxUI = Messaging.getInboxUI(for: inboxSurface)}var body: some View {NavigationView {inboxUI.view.navigationTitle("Inbox")}.onAppear {let inboxSurface = Surface(path: "inbox")Messaging.updatePropositionsForSurfaces([inboxSurface])}}}
UIKit Application
To display an Inbox in UIKit, wrap the SwiftUI InboxUI.view using UIHostingController.
Copied to your clipboardimport UIKitimport SwiftUIimport AEPMessagingclass InboxViewController: UIViewController {var inboxUI: InboxUI!override func viewDidLoad() {super.viewDidLoad()title = "Inbox"let inboxSurface = Surface(path: "inbox")inboxUI = Messaging.getInboxUI(for: inboxSurface)let hostingController = UIHostingController(rootView: inboxUI.view)addChild(hostingController)view.addSubview(hostingController.view)hostingController.didMove(toParent: self)hostingController.view.translatesAutoresizingMaskIntoConstraints = falseNSLayoutConstraint.activate([hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)])Messaging.updatePropositionsForSurfaces([inboxSurface])}}
Refreshing Inbox Data
The Inbox provides two ways to refresh content.
Pull-to-Refresh
Enable pull-to-refresh to let users refresh content by pulling down on the Inbox.
Copied to your clipboardlet inboxSurface = Surface(path: "inbox")let inboxUI = Messaging.getInboxUI(for: inboxSurface)inboxUI.isPullToRefreshEnabled = true
Pull-to-refresh is disabled by default. Set isPullToRefreshEnabled = true to enable it.
Programmatic Refresh
Call refresh() to programmatically trigger a content refresh.
Copied to your clipboardinboxUI.refresh()
Best Practices
Fetch Early: Call
updatePropositionsForSurfaceswhen your app launches or when the user navigates to the Inbox screen to ensure fresh content is available.Surface Naming: Use descriptive surface paths that match your Adobe Journey Optimizer campaign configuration (e.g.,
Surface(path: "inbox"),Surface(path: "home_feed")).Reuse InboxUI: Keep the
InboxUIinstance alive as long as the Inbox view is visible. TheInboxUImaintains state and efficiently updates when content changes.Handle Multiple Surfaces: If your app has multiple Inboxes, create separate
InboxUIinstances with different surfaces.
Copied to your clipboardlet notificationsInboxUI = Messaging.getInboxUI(for: Surface(path: "notifications"))let promotionsInboxUI = Messaging.getInboxUI(for: Surface(path: "promotions"))
Next Steps
- Listening to Inbox Events - Learn how to respond to user interactions
- Customizing Your Inbox - Customize appearance, spacing, and views
