iOS – Handling Events

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

User Generated Events

Closing the paywall

If the close button is visible and the user presses it, this method will be invoked:

public func paywallControllerDidPressCloseButton(_ controller: AdaptyPaywallController) {
    controller.dismiss(animated: true)
}

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:

public func paywallControllerDidCancelPurchase(_ controller: AdaptyPaywallController) {
}

Successful purchase

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

public func paywallController(_ controller: AdaptyPaywallController,
                              didFinishPurchaseWith profile: AdaptyProfile) {      
    controller.dismiss(animated: true)
}

We recommend to dismiss the screen in that case.

Failed purchase

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

public func paywallController(_ controller: AdaptyPaywallController,
                              didFailPurchaseWith 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 policy: AdaptyProductsFetchPolicy,
                              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.

Overriding Behaviours

URL opening behaviour

By default, AdaptyUI will open URLs in the default browser. If you want to change this behavior, please implement the following method:

public func paywallController(_ controller: AdaptyPaywallController, openURL url: URL) {
    UIApplication.shared.open(url, options: [:]) // the default behaviour
}

Presenting messages to user

We often have a situation where we need to show a message to a user. It can be, for example, an error that occurred during the purchase process, or, on the contrary, a message about successfully restored purchases. By default we show messages with texts in English using the UIAlertController, but if you need to customize this behavior, implement the following method:

public func paywallController(_ controller: AdaptyPaywallController,
                              buildDialogWith event: AdaptyUI.Event,
                              onDialogDismissed: (() -> Void)?) -> UIViewController {
    // the default behaviour:
    switch event {
    case .restored:
        return UIAlertController.buildRestoredAlert(onDialogDismissed: onDialogDismissed)
    case let .error(error):
        return UIAlertController.buildErrorAlert(error, onDialogDismissed: onDialogDismissed)
    }
}

🚧

If you have custom dialogs, be sure to call the onDialogDismissed function so that the AdaptyUI understands when you can continue.