Skip to main content

iOS - Present Paywall Builder paywalls in Observer mode

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 section refers to Observer mode only. If you do not work in the Observer mode, refer to the iOS - Present Paywall Builder paywalls.

Before you start presenting paywalls (Click to Expand)
  1. Set up initial integration of Adapty with the Google Play and with the App Store.
  2. Install and configure Adapty SDK. Make sure to set the observerMode parameter to true. Refer to our framework-specific instructions for iOS, for Android, for Flutter, for React Native, and for Unity.
  3. Create products in the Adapty Dashboard.
  4. Configure paywalls, assign products to them, and customize them using Paywall Builder in the Adapty Dashboard.
  5. Create placements and assign your paywalls to them in the Adapty Dashboard.
  6. Fetch Paywall Builder paywalls and their configuration in your mobile app code.

  1. Implement the AdaptyObserverModeResolver object:

    Swift
    func observerMode(didInitiatePurchase product: AdaptyPaywallProduct,
    onStartPurchase: @escaping () -> Void,
    onFinishPurchase: @escaping () -> Void) {
    // use the product object to handle the purchase
    // use the onStartPurchase and onFinishPurchase callbacks to notify AdaptyUI about the process of the purchase
    }

    The observerMode(didInitiatePurchase:onStartPurchase:onFinishPurchase:) event will inform you that the user has initiated a purchase. You can trigger your custom purchase flow in response to this callback.

    Also, remember to invoke the following callbacks to notify AdaptyUI about the process of the purchase. This is necessary for proper paywall behavior, such as showing the loader, among other things:

    CallbackDescription
    onStartPurchase()The callback should be invoked to notify AdaptyUI that the purchase is started.
    onFinishPurchase()The callback should be invoked to notify AdaptyUI that the purchase is finished.
  2. Create a paywall configuration object:

    Swift
    do {
    let paywallConfiguration = try AdaptyUI.getPaywallConfiguration(
    forPaywall: <paywall object>,
    observerModeResolver: <AdaptyObserverModeResolver>
    )
    } catch {
    // handle the error
    }

    Request parameters:

    ParameterPresenceDescription
    PaywallrequiredAn AdaptyPaywall object to obtain a controller for the desired paywall.
    ObserverModeResolverrequiredThe AdaptyObserverModeResolver object you've implemented in the previous step
  3. 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

After the object has been successfully created, you can display it like so:

Swift
present(visualPaywall, animated: true)
warning

Don't forget to Associate paywalls to purchase transactions. Otherwise, Adapty will not determine the source paywall of the purchase.