Skip to main content

Present new Paywall Builder paywalls in iOS SDK

If you've customized 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.

warning

This guide is for new Paywall Builder paywalls . The process for presenting paywalls differs for paywalls designed with different versions of Paywall Builder, remote config paywalls, and Observer mode.

Present paywalls in SwiftUI

In order to display the visual paywall on the device screen, use the .paywall modifier in SwiftUI:

SwiftUI
@State var paywallPresented = false // ensure that you manage this variable state and set it to `true` at the moment you want to show the paywall

var body: some View {
Text("Hello, AdaptyUI!")
.paywall(
isPresented: $paywallPresented,
paywallConfiguration: <AdaptyUI.PaywallConfiguration>,
didPerformAction: { action in
switch action {
case .close:
paywallPresented = false
default:
// Handle other actions
break
}
},
didFinishPurchase: { product, profile in paywallPresented = false },
didFailPurchase: { product, error in /* handle the error */ },
didFinishRestore: { profile in /* check access level and dismiss */ },
didFailRestore: { error in /* handle the error */ },
didFailRendering: { error in paywallPresented = false }
)
}

Parameters:

ParameterRequiredDescription
isPresentedrequiredA binding that manages whether the paywall screen is displayed.
paywallConfigurationrequiredAn AdaptyUI.PaywallConfiguration object containing visual details of the paywall. Use the AdaptyUI.paywallConfiguration(for:products:viewConfiguration:observerModeResolver:tagResolver:timerResolver:) method. Refer to Fetch Paywall Builder paywalls and their configuration topic for more details.
didFailPurchaserequiredInvoked when Adapty.makePurchase() fails.
didFinishRestorerequiredInvoked when Adapty.restorePurchases() completes successfully.
didFailRestorerequiredInvoked when Adapty.restorePurchases() fails.
didFailRenderingrequiredInvoked if an error occurs while rendering the interface. In this case, contact Adapty Support.
fullScreenoptionalDetermines if the paywall appears in full-screen mode or as a modal. Defaults to true.
didAppearoptionalInvoked when the paywall view was presented.
didDisappearoptionalInvoked when the paywall view was dismissed.
didPerformActionoptionalInvoked when a user clicks a button. Different buttons have different action IDs. Two action IDs are pre-defined: close and openURL, while others are custom and can be set in the builder.
didSelectProductoptionalIf the product was selected for purchase (by a user or by the system), this callback will be invoked.
didStartPurchaseoptionalInvoked when the user begins the purchase process.
didFinishPurchaseoptionalInvoked when Adapty.makePurchase() completes successfully.
didFinishWebPaymentNavigationoptionalInvoked when web payment navigation finishes.
didStartRestoreoptionalInvoked when the user starts the restore process.
didFailLoadingProductsoptionalInvoked when errors occur during product loading. Return true to retry loading.
didPartiallyLoadProductsoptionalInvoked when products are partially loaded.
showAlertItemoptionalA binding that manages the display of alert items above the paywall.
showAlertBuilderoptionalA function for rendering the alert view.
placeholderBuilderoptionalA function for rendering the placeholder view while the paywall is loading.

Refer to the iOS - Handling events topic for more details on parameters.

Present paywalls in UIKit

In order to display the visual paywall on the device screen, do the following:

  1. Initialize the visual paywall you want to display by using the .paywallController(for:products:viewConfiguration:delegate:) method:

    Swift
    import Adapty
    import AdaptyUI

    let visualPaywall = AdaptyUI.paywallController(
    with: <paywall configuration object>,
    delegate: <AdaptyPaywallControllerDelegate>
    )

    Request parameters:

    ParameterPresenceDescription
    paywall configurationrequiredAn AdaptyUI.PaywallConfiguration object containing visual details of the paywall. Use the AdaptyUI.getPaywallConfiguration(forPaywall:locale:) method. Refer to Fetch Paywall Builder paywalls and their configuration topic for more details.
    delegaterequiredAn AdaptyPaywallControllerDelegate to listen to paywall events. Refer to Handling paywall events topic for more details.

    Returns:

    ObjectDescription
    AdaptyPaywallControllerAn object, representing the requested paywall screen
  2. After the object has been successfully created, you can display it on the screen of the device:

    Swift
    present(visualPaywall, animated: true)
tip

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.