Get flows & paywalls - iOS
getFlow retrieves After you designed your flow, you can display it in your mobile app. The first step is to get the flow or paywall associated with the placement and its view configuration as described below.
Want to see a real-world example of how Adapty SDK is integrated into a mobile app? Check out our sample apps, which demonstrate the full setup, including displaying paywalls, making purchases, and other basic functionality.
Before you start
You need:
-
Products in the Adapty Dashboard: Create your products.
-
A flow with products: Build it in the Flow & Paywall Builder and assign products to it.
-
A placement: Create a placement and assign your flow to it.
-
Adapty SDK installed: See the iOS SDK installation guide.
Starting from SDK 4.4, flows require iOS 16 or later. To build an app that supports iOS 15, mark the types that use flows with
@available(iOS 16.0, *), and open the flow insideif #available(iOS 16.0, *). In theelsebranch, show your own content, such as a custom paywall.
Fetch flow/paywall
If you’ve designed a flow or paywall in the builder, you don’t need to worry about rendering it in your mobile app code to display it to the user. Such a flow or paywall contains both what should be shown within it and how it should be shown. Nevertheless, you need to get its ID via the placement, its view configuration, and then present it in your mobile app.
Fetch the flow or paywall and its view configuration as early as possible — ideally well before you present it. As soon as you fetch the view configuration, the SDK starts downloading and caching its images in the background. The earlier you fetch it, the more time these downloads have to complete. By the time you present the flow or paywall, its configuration and images can already be cached and ready to display.
To warm several placements at once, call preloadFlows (iOS SDK 4.1+). It caches the placement JSON only, so you still fetch the view configuration to get the layout and images.
To get a flow or paywall, use the getFlow method:
do {
let flow = try await Adapty.getFlow(placementId: "YOUR_PLACEMENT_ID")
// the requested flow/paywall
} catch {
// handle the error
}Parameters:
| Parameter | Presence | Description |
|---|---|---|
| placementId | required | The identifier of the desired Placement. This is the value you specified when creating a placement in the Adapty Dashboard. |
| fetchPolicy | default: .reloadRevalidatingCacheData |
However, if you believe your users deal with unstable internet, consider A third policy, Note that the cache remains intact upon restarting the app and is only cleared when the app is reinstalled or through manual cleanup. Adapty SDK stores paywalls locally in two layers: regularly updated cache described above and fallback paywalls. We also use CDN to fetch paywalls faster and a stand-alone fallback server in case the CDN is unreachable. This system is designed to make sure you always get the latest version of your paywalls while ensuring reliability even in cases where internet connection is scarce. |
| loadTimeout | default: 5 sec | This value limits the timeout for this method. If the Adapty server doesn’t respond in time or returns an error, the SDK returns the cached flow. If nothing is cached and the server timed out or returned a server error, the SDK requests the flow from the fallback server (a CDN copy that serves only the placement’s All Users audience). As a last resort, the SDK returns the flow from your fallback file. Note that in rare cases this method can timeout slightly later than specified in |
Response parameters:
| Parameter | Description |
|---|---|
| Flow | An AdaptyFlow object containing the placement, identifiers (id, variationId), variation name (variationName, optional, SDK 4.2+), name, its paywall variations (paywalls), remote configs, and a hasViewConfiguration flag indicating whether the flow includes a view configuration. To fetch the actual products for pre-loading, custom UI, or programmatic checks, call getPaywallProducts(flow:). |
Fetch the view configuration
After fetching the flow or paywall, check whether it includes a view configuration via flow.hasViewConfiguration. The flag distinguishes how the placement was designed in the Adapty Dashboard:
true— the placement was designed in the Flow & Paywall Builder (a flow) or the old Paywall Builder (a paywall). Adapty renders the UI for you. Continue with the steps below to fetch the view configuration and present the flow or paywall.false— the placement is a custom paywall with no Builder UI.
Use the getFlowConfiguration method to load the view configuration.
import AdaptyUI
import AdaptyUIBuilder
guard flow.hasViewConfiguration else {
// handle as custom paywall
return
}
let flowConfiguration = try await AdaptyUI.getFlowConfiguration(
forFlow: flow,
preferredLocales: Locale.preferredLanguages
)Parameters:
| Parameter | Presence | Description |
|---|---|---|
| forFlow | required | An AdaptyFlow object obtained via Adapty.getFlow. |
| preferredLocales | required SDK 4.5+ | The user’s languages, most preferred first, such as Locale.preferredLanguages. The SDK tries these languages in order and matches the first one that the flow has. With an empty list or no match, the user sees the flow in its default locale. For paywalls from the old Paywall Builder, the SDK only matches the user’s language with the highest priority. Replaces locale from SDK 4.0–4.4. For which list to pass, read Pass the user’s languages to the SDK. |
| locale | optional default: SDK 4.0–4.4 | The identifier of the flow localization to render the view with — for example, en or pt-BR. Your app decides which code to pass, such as the device locale or the language from a picker in your app. Omit it and the view renders in en, or in the flow’s default localization when the flow has no en. The code must match a localization code of the flow exactly. See Pass the user’s languages to the SDK. |
| localizationStrategy | optional default: SDK 4.5+ | Sets how the SDK matches the user’s languages with the locales of the flow. The default fits most apps. For the other values, read Select a localization strategy. |
| customLayoutId | optional default: SDK 4.1+ | The custom ID of a layout in the flow’s layout configuration. Pass it to render that specific layout instead of the one the SDK picks automatically from the device type and screen size. If no layout matches the ID, the call fails with a no-view-configuration error. The Flow & Paywall Builder doesn’t assign custom layout IDs yet, so leave this unset. |
| loadTimeout | default: 5 sec | This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned. Note that in rare cases this method can timeout slightly later than specified in loadTimeout, since the operation may consist of different requests under the hood. |
| products | optional | Provide an array of AdaptyPaywallProduct objects to optimize the display timing of products on the screen. If nil is passed, AdaptyUI will automatically fetch the necessary products. |
| tagResolver | optional | Your app’s values for the flow’s custom tags, in a [String: String] dictionary keyed by each tag’s full name, or in an object conforming to AdaptyTagResolver. For details, read Pass data to flows. |
| timerResolver | optional | An object conforming to AdaptyTimerResolver that returns the end date of each Developer defined timer in the flow, by Timer ID. See Set up developer-defined timers. |
| assetsResolver | optional | A [String: AdaptyCustomAsset] dictionary that overrides images and videos in the flow/paywall. See Customize assets. |
| customElementsResolver | optional SDK 4.4+ | Your app’s native views for the flow’s custom elements, in an object conforming to AdaptyUICustomElementsResolver, or in a [String: AdaptyUICustomElementBuilder] dictionary keyed by Type. Replaces the app-wide resolver in this flow. For details, read Display custom elements. |
| systemRequestsHandler | optional | An object conforming to AdaptySystemRequestsHandler that asks iOS for a permission when the flow requests one, and returns the user’s answer to the flow. Pass it if the flow has the Request permission action: without a handler, the flow stays on the screen that sent the request. For details, read Handle permission requests in flows. |
Once loaded, present the flow/paywall.
Get a flow or paywall for a default audience to fetch it faster
Typically, flows and paywalls are fetched almost instantly, so you don’t need to worry about speeding up this process. However, in cases where you have numerous audiences and placements, and your users have a weak internet connection, fetching a flow or paywall may take longer than you’d like. In such situations, you might want to display a default flow or paywall to ensure a smooth user experience rather than showing nothing at all.
To address this, you can use the getFlowForDefaultAudience method, which fetches the flow or paywall of the specified placement for the All Users audience. However, it’s crucial to understand that the recommended approach is to fetch the flow or paywall by the getFlow method, as detailed in the Fetch Paywall Information section above.
The getFlowForDefaultAudience method has two drawbacks:
- Same flow for all app versions: Older app versions may load a flow they can’t display. If the flow uses a feature of a later Adapty SDK, branch it by SDK version.
- No targeting: Every user sees the flow for the All Users audience, so you can’t target by country, attribution, or custom attributes.
To avoid both, use getFlow instead.
Adapty.getFlowForDefaultAudience(placementId: "YOUR_PLACEMENT_ID") { result in
switch result {
case let .success(flow):
// the requested flow
case let .failure(error):
// handle the error
}
}| Parameter | Presence | Description |
|---|---|---|
| placementId | required | The identifier of the Placement. This is the value you specified when creating a placement in your Adapty Dashboard. |
| fetchPolicy | default: .reloadRevalidatingCacheData |
However, if you believe your users deal with unstable internet, consider A third policy, Note that the cache remains intact upon restarting the app and is only cleared when the app is reinstalled or through manual cleanup. |
Customize assets
To customize images and videos in your paywall/flow, implement the custom assets.
Hero images and videos have predefined IDs: hero_image and hero_video. In a custom asset bundle, you target these elements by their IDs and customize their behavior.
For other images and videos, you need to set a custom ID in the Adapty dashboard.
For example, you can:
- Show a different image or video to some users.
- Show a local preview image while a remote main image is loading.
- Show a preview image before running a video.
- Show media bundled with the app, so the first screen renders without a download. See Show first-screen media from the app bundle.
- Provide a video’s pixel resolution so the player reserves layout space (aspect ratio =
width / height) before the video loads. Passnilto skip this.
Here’s an example of how you can provide custom assets via a simple dictionary:
let customAssets: [String: AdaptyCustomAsset] = [
// Show a local image using a custom ID
"custom_image": .image(
.uiImage(value: UIImage(named: "image_name")!)
),
// Show a local preview image while a remote main image is loading
"hero_image": .image(
.remote(
url: URL(string: "https://example.com/image.jpg")!,
preview: UIImage(named: "preview_image")
)
),
// Show a local video with a preview image and a known resolution
"hero_video": .video(
.file(
url: Bundle.main.url(forResource: "custom_video", withExtension: "mp4")!,
preview: .uiImage(value: UIImage(named: "video_preview")!),
resolution: CGSize(width: 1080, height: 1920)
)
),
]
let flowConfig = try await AdaptyUI.getFlowConfiguration(
forFlow: flow,
assetsResolver: customAssets
)If an asset is not found, the paywall/flow will fall back to its default appearance.
Set up developer-defined timers
Use this section for a timer with the Developer defined behavior in the Flow & Paywall Builder. In the builder, each such timer has a Timer ID (see Let your app set the end date), and your app sets the end date for it. Use the same Timer ID in your code as in the builder, character for character, including letter case and spaces. If the IDs differ, the timer gets no end date from your app.
To set the end dates, create an object that conforms to the AdaptyTimerResolver protocol. The object returns the end date for each Timer ID. You can also use a [String: Date] dictionary, because it already conforms to this protocol. Here is an example:
@MainActor
struct AdaptyTimerResolverImpl: AdaptyTimerResolver {
func timerEndAtDate(for timerId: String) -> Date {
switch timerId {
case "CUSTOM_TIMER_6H":
Date(timeIntervalSinceNow: 3600.0 * 6.0) // 6 hours
case "CUSTOM_TIMER_NY":
Calendar.current.nextDate(
after: Date(),
matching: DateComponents(month: 1, day: 1),
matchingPolicy: .nextTime
) ?? Date(timeIntervalSinceNow: 3600.0) // next New Year's Day
default:
Date(timeIntervalSinceNow: 3600.0) // 1 hour
}
}
}Pass the resolver to the timerResolver parameter of getFlowConfiguration:
do {
let flowConfiguration = try await AdaptyUI.getFlowConfiguration(
forFlow: flow,
timerResolver: AdaptyTimerResolverImpl()
)
// present the flow
} catch {
// handle the error
}In this example, CUSTOM_TIMER_NY and CUSTOM_TIMER_6H are the Timer IDs of two Developer defined timers in the builder:
CUSTOM_TIMER_NY: The time left until the next New Year’s Day.CUSTOM_TIMER_6H: A 6-hour countdown that starts again each time the user opens the screen.
The SDK calls the resolver each time a screen with the timer opens. If the resolver returns a date in the past, the timer shows zero at once and its On timer end trigger runs. If you pass no resolver, or a dictionary with no key for a Timer ID, the timer counts down one hour from the screen open.
After you designed the visual part for your paywall with the Paywall Builder in the Adapty Dashboard, you can display it in your mobile app. The first step is to get the paywall associated with the placement and its view configuration as described below.
Please be aware that this topic refers to Paywall Builder-customized paywalls. If you implement custom paywalls, refer to Fetch custom paywalls and products.
Want to see a real-world example of how Adapty SDK is integrated into a mobile app? Check out our sample apps, which demonstrate the full setup, including displaying paywalls, making purchases, and other basic functionality.
Before you start displaying paywalls in your mobile app
- Create your products in the Adapty Dashboard.
- Create a paywall and incorporate the products into it in the Adapty Dashboard.
- Create placements and incorporate your paywall into it in the Adapty Dashboard.
- Install Adapty SDK in your mobile app.
Fetch paywall designed with Paywall Builder
If you’ve designed a paywall using the Paywall Builder, you don’t need to worry about rendering it in your mobile app code to display it to the user. Such a paywall contains both what should be shown within the paywall and how it should be shown. Nevertheless, you need to get its ID via the placement, its view configuration, and then present it in your mobile app.
To ensure optimal performance, it’s crucial to retrieve the paywall and its view configuration as early as possible, allowing sufficient time for images to download before presenting them to the user.
To get a paywall, use the getPaywall method:
do {
let paywall = try await Adapty.getPaywall("YOUR_PLACEMENT_ID")
// the requested paywall
} catch {
// handle the error
}Parameters:
| Parameter | Presence | Description |
|---|---|---|
| placementId | required | The identifier of the desired Placement. This is the value you specified when creating a placement in the Adapty Dashboard. |
| locale | optional default: | The identifier of the paywall localization. This parameter is expected to be a language code composed of one or two subtags separated by the minus (-) character. The first subtag is for the language, the second one is for the region. Example: See Localizations and locale codes for more information on locale codes and how we recommend using them. |
| fetchPolicy | default: .reloadRevalidatingCacheData |
However, if you believe your users deal with unstable internet, consider A third policy, Note that the cache remains intact upon restarting the app and is only cleared when the app is reinstalled or through manual cleanup. Adapty SDK stores paywalls locally in two layers: regularly updated cache described above and fallback paywalls. We also use CDN to fetch paywalls faster and a stand-alone fallback server in case the CDN is unreachable. This system is designed to make sure you always get the latest version of your paywalls while ensuring reliability even in cases where internet connection is scarce. |
| loadTimeout | default: 5 sec | This value limits the timeout for this method. If the Adapty server doesn’t respond in time or returns an error, the SDK returns the paywall from the fallback server (a CDN copy that serves only the placement’s All Users audience), the cache, or your fallback file. Note that in rare cases this method can timeout slightly later than specified in |
Response parameters:
| Parameter | Description |
|---|---|
| Paywall | An AdaptyPaywall object with a list of product IDs, the paywall identifier, remote config, and several other properties. |
Fetch the view configuration of paywall designed using Paywall Builder
Make sure to enable the Show on device toggle in the paywall builder. If this option isn’t turned on, the view configuration won’t be available to retrieve.
After fetching the paywall, check if it includes a view configuration, which indicates that it was created using Paywall Builder. This will guide you on how to display the paywall. If the view configuration is present, treat it as a Paywall Builder paywall; if not, handle it as a custom paywall.
Use the getPaywallConfiguration method to load the view configuration.
import AdaptyUI
import AdaptyUIBuilder
guard paywall.hasViewConfiguration else {
// use your custom logic
return
}
do {
let paywallConfiguration = try await AdaptyUI.getPaywallConfiguration(
forPaywall: paywall,
products: products
)
// use loaded configuration
} catch {
// handle the error
}Parameters:
| Parameter | Presence | Description |
|---|---|---|
| paywall | required | An AdaptyPaywall object to obtain a controller for the desired paywall. |
| loadTimeout | default: 5 sec | This value limits the timeout for this method. If the timeout is reached, cached data or local fallback will be returned. Note that in rare cases this method can timeout slightly later than specified in loadTimeout, since the operation may consist of different requests under the hood. |
| products | optional | Provide an array of AdaptyPaywallProduct objects to optimize the display timing of products on the screen. If nil is passed, AdaptyUI will automatically fetch the necessary products. |
If you support multiple languages, add a localization to your paywall. For the codes to use, see Localizations and locale codes.
Once loaded, present the paywall.
Get a paywall for a default audience to fetch it faster
Typically, paywalls are fetched almost instantly, so you don’t need to worry about speeding up this process. However, in cases where you have numerous audiences and paywalls, and your users have a weak internet connection, fetching a paywall may take longer than you’d like. In such situations, you might want to display a default paywall to ensure a smooth user experience rather than showing no paywall at all.
To address this, you can use the getPaywallForDefaultAudience method, which fetches the paywall of the specified placement for the All Users audience. However, it’s crucial to understand that the recommended approach is to fetch the paywall by the getPaywall method, as detailed in the Fetch Paywall Information section above.
Why we recommend using getPaywall
The getPaywallForDefaultAudience method comes with a few significant drawbacks:
- Potential backward compatibility issues: If you need to show different paywalls for different app versions (current and future), you may face challenges. You’ll either have to design paywalls that support the current (legacy) version or accept that users with the current (legacy) version might encounter issues with non-rendered paywalls.
- Loss of targeting: All users will see the same paywall designed for the All Users audience, which means you lose personalized targeting (including based on countries, marketing attribution or your own custom attributes).
If you’re willing to accept these drawbacks to benefit from faster paywall fetching, use the getPaywallForDefaultAudience method as follows. Otherwise stick to getPaywall described above.
Adapty.getPaywallForDefaultAudience(placementId: "YOUR_PLACEMENT_ID", locale: "en") { result in
switch result {
case let .success(paywall):
// the requested paywall
case let .failure(error):
// handle the error
}
}The getPaywallForDefaultAudience method is available starting from iOS SDK version 2.11.2.
| Parameter | Presence | Description |
|---|---|---|
| placementId | required | The identifier of the Placement. This is the value you specified when creating a placement in your Adapty Dashboard. |
| locale | optional default: | The identifier of the paywall localization. This parameter is expected to be a language code composed of one or more subtags separated by the minus (-) character. The first subtag is for the language, the second one is for the region. Example: See Localizations and locale codes for more information on locale codes and how we recommend using them. |
| fetchPolicy | default: .reloadRevalidatingCacheData |
However, if you believe your users deal with unstable internet, consider A third policy, Note that the cache remains intact upon restarting the app and is only cleared when the app is reinstalled or through manual cleanup. |
Customize assets
To customize images and videos in your paywall, implement the custom assets.
Hero images and videos have predefined IDs: hero_image and hero_video. In a custom asset bundle, you target these elements by their IDs and customize their behavior.
For other images and videos, you need to set a custom ID in the Adapty dashboard.
For example, you can:
- Show a different image or video to some users.
- Show a local preview image while a remote main image is loading.
- Show a preview image before running a video.
To use this feature, update the Adapty iOS SDK to version 3.7.0 or higher.
Here’s an example of how you can provide custom assets via a simple dictionary:
let customAssets: [String: AdaptyCustomAsset] = [
// Show a local image using a custom ID
"custom_image": .image(
.uiImage(value: UIImage(named: "image_name")!)
),
// Show a local preview image while a remote main image is loading
"hero_image": .image(
.remote(
url: URL(string: "https://example.com/image.jpg")!,
preview: UIImage(named: "preview_image")
)
),
// Show a local video with a preview image
"hero_video": .video(
.file(
url: Bundle.main.url(forResource: "custom_video", withExtension: "mp4")!,
preview: .uiImage(value: UIImage(named: "video_preview")!)
)
),
]
let paywallConfig = try await AdaptyUI.getPaywallConfiguration(
forPaywall: paywall,
assetsResolver: customAssets
)If an asset is not found, the paywall will fall back to its default appearance.
Set up developer-defined timers
To use custom timers in your mobile app, create an object that follows the AdaptyTimerResolver protocol. This object defines how each custom timer should be rendered. If you prefer, you can use a [String: Date] dictionary directly, as it already conforms to this protocol. Here is an example:
@MainActor
struct AdaptyTimerResolverImpl: AdaptyTimerResolver {
func timerEndAtDate(for timerId: String) -> Date {
switch timerId {
case "CUSTOM_TIMER_6H":
Date(timeIntervalSinceNow: 3600.0 * 6.0) // 6 hours
case "CUSTOM_TIMER_NY":
Calendar.current.date(from: DateComponents(year: 2025, month: 1, day: 1)) ?? Date(timeIntervalSinceNow: 3600.0)
default:
Date(timeIntervalSinceNow: 3600.0) // 1 hour
}
}
}In this example, CUSTOM_TIMER_NY and CUSTOM_TIMER_6H are the Timer IDs of developer-defined timers you set in the Adapty Dashboard. The timerResolver ensures your app dynamically updates each timer with the correct value. For example:
CUSTOM_TIMER_NY: The time remaining until the timer’s end, such as New Year’s Day.CUSTOM_TIMER_6H: The time left in a 6-hour period that started when the user opened the paywall.