Offline Content Card Availability
This tutorial explains how to enable offline availability for Content Cards, allowing them to display when your app launches without a network connection.
Overview
When offline availability is enabled, Content Cards fetched from Adobe Journey Optimizer are persisted to the device. On the next app launch, the SDK loads them from disk before any network response arrives, so users see content immediately regardless of connectivity.
data-variant=info
data-slots=text
Pre-requisites
- Integrate and register the AEPMessaging extension in your app.
- Ensure you are using AEPMessaging version 5.16.0 or later (which requires AEPCore and AEPServices 5.11.0 or later).
Step 1: Enable offline availability in Tags
- Sign in to Adobe Experience Platform Data Collection and open Tags.
- Select your mobile property and open the Adobe Journey Optimizer extension configuration.
- Enable the Content Card Offline Availability setting.
- Save and publish your Tags configuration.
Once enabled, Content Cards returned by any successful updatePropositionsForSurfaces call are automatically written to a disk cache.
Step 2: Fetch Content Cards as usual
No code changes are required to enable persistence. Continue calling updatePropositionsForSurfaces as you normally would. When the device is online and the call succeeds, the SDK automatically writes the returned cards to disk.
data-slots=heading, code
data-repeat=1
Swift
let homePageSurface = Surface(path: "homepage")
Messaging.updatePropositionsForSurfaces([homePageSurface])
Step 3: Retrieve Content Cards — with or without a network call
This is where offline availability is leveraged. You can call getContentCardsUI without calling updatePropositionsForSurfaces first in the current session. If a prior session successfully fetched cards for the surface and the offline feature was enabled, the SDK loads those cards from the disk cache and returns them immediately — even with no network connection.
data-slots=heading, code
data-repeat=1
Swift
let homePageSurface = Surface(path: "homepage")
// Cards are served from the disk cache if a prior session fetched them successfully —
// no updatePropositionsForSurfaces call is needed in the current session
Messaging.getContentCardsUI(for: homePageSurface) { result in
switch result {
case .success(let contentCards):
// display contentCards
case .failure(let error):
// handle error
}
}
data-variant=warning
data-slots=text
getContentCardsUI only returns cards from the disk cache when all of the following conditions are met: the Content Card Offline Availability setting was enabled in Tags when the cards were originally fetched, a prior session had a successful updatePropositionsForSurfaces call for that surface, and the setting is still enabled in the current session. If the setting is disabled after cards have been persisted, the SDK clears the disk cache and filters out any disk-origin cards — so turning the feature off removes offline availability immediately, even for previously cached content. If none of the conditions are met, the result is empty until updatePropositionsForSurfaces succeeds in the current session.Step 4: Clear the cache when needed
Use clearCachedPropositions to remove all persisted Content Cards and the in-memory cache. This is useful, for example, when a user logs out.
data-slots=heading, code
data-repeat=1
Swift
Messaging.clearCachedPropositions()
data-variant=info
data-slots=text
MobileCore.resetIdentities() also automatically clears persisted Content Cards, ensuring cached content is never carried across user identities.How it works
clearCachedPropositions calledMobileCore.resetIdentities() calledTracking and analytics
The SDK sends a decisioning.propositionDisplay event to Adobe Experience Platform when a Content Card is displayed. Each card item in that event includes a servedFromPersistentCache flag under items[].data.characteristics:
falsetrueThe following example shows the relevant portion of a display event as captured in Assurance:
{
"xdm": {
"eventType": "decisioning.propositionDisplay",
"_experience": {
"decisioning": {
"propositionEventType": { "display": 1 },
"propositions": [
{
"id": "c1984e87-6c5e-4441-8691-f148af4975d8",
"scope": "mobileapp://com.example.app/homepage",
"items": [
{
"id": "cd20a906-f444-45fe-bdd8-868acc8a00b0",
"data": {
"characteristics": {
"servedFromPersistentCache": true
}
}
}
]
}
]
}
}
}
}