iOS – Handling events

If you need to control or monitor the processes that take place on the purchase screen, you need to implement the AdaptyPaywallControllerDelegate methods.

User generated events

Actions

If user has performed some action, this method will be invoked:

func paywallController(_ controller: AdaptyPaywallController,
                       didPerform action: AdaptyUI.Action) {

    switch action {
        case .close:
            controller.dismiss(animated: true)
        case let .openURL(url):
            UIApplication.shared.open(url, options: [:])
        case let .custom(id):
            if id == "login" {
               // implement login flow 
            }
            break
    }
}

At the moment there are three types of actions supported: close, openURL(url:) and custom(id:). For example, if user presses the close button, the action close will occur and you are supposed to dismiss the paywall.

💡

Login Action

If you have configured Login Action in the dashboard, you should implement reaction for custom action with id "login"

Product selection

If product was selected for purchase by user, this method will be invoked.

    func paywallController(_ controller: AdaptyPaywallController,
                           didSelectProduct product: AdaptyPaywallProduct) {
    }

Started purchase

If user initiates the purchase process, this method will be invoked.

func paywallController(_ controller: AdaptyPaywallController,
                       didStartPurchase product: AdaptyPaywallProduct) {
}

Canceled purchase

If the user initiates the purchase process but manually interrupts it, this function will be called. Basically, this event occurs when the Adapty.makePurchase() function completes with a .paymentCancelled error:

func paywallController(_ controller: AdaptyPaywallController,
                       didCancelPurchase product: AdaptyPaywallProduct) {
}

Successful purchase

If Adapty.makePurchase() succeeds, this method will be invoked:

func paywallController(_ controller: AdaptyPaywallController,
                       didFinishPurchase product: AdaptyPaywallProduct,
                       purchasedInfo: AdaptyPurchasedInfo) {      
    controller.dismiss(animated: true)
}

We recommend to dismiss the screen in that case.

Failed purchase

If Adapty.makePurchase() fails, this method will be invoked:

func paywallController(_ controller: AdaptyPaywallController,
                       didFailPurchase product: AdaptyPaywallProduct,
                       error: AdaptyError) {
}

Successful restore

If Adapty.restorePurchases() succeeds, this method will be invoked:

func paywallController(_ controller: AdaptyPaywallController, 
                       didFinishRestoreWith profile: AdaptyProfile) {
}

We recommend to dismiss the screen if the user has the required accessLevel.

Failed restore

If Adapty.restorePurchases() fails, this method will be invoked:

public func paywallController(_ controller: AdaptyPaywallController, 
                              didFailRestoreWith error: AdaptyError) {
}

Data fetching and rendering

Products loading errors

If you didn't pass the product array during initialization, AdaptyUI will retrieve the necessary objects from the server by itself. In this case, this operation may fail, and AdaptyUI will report the error by invoking this method:

public func paywallController(_ controller: AdaptyPaywallController,
                              didFailLoadingProductsWith error: AdaptyError) -> Bool {
    return true
}

If you return true, AdaptyUI will repeat the request after 2 seconds.

Rendering errors

If an error occurs during the interface rendering, it will be reported by calling this method:

public func paywallController(_ controller: AdaptyPaywallController,
                              didFailRenderingWith error: AdaptyError) {
}

In a normal situation such errors should not occur, so if you come across one, please let us know about it.