If you want complete control over the paywall presentation process, you can use getPaywall(forEvent:params:paywallOverrides:delegate:). This returns the UIViewController subclass PaywallViewController, which you can then present however you like. Or, you can use a SwiftUI View via PaywallView. The following is code is how you’d mimic register:

This does the following:

  1. Gets the paywall view controller.
  2. Handles the cases where the paywall was skipped.
  3. Catches any presentation errors.
  4. Implements the delegate. This is called when the user is finished with the paywall. First, it checks shouldDismiss. If this is true then is dismissed the paywall from view before launching any features. This may depend on the result depending on how you first presented your view. Then, it switches over the result. If the result is purchased or restored the feature can be launched. However, if the result is declined, it checks that the the featureGating property of paywall.info is nonGated and that the closeReason isn’t .forNextPaywall.

Best practices

  1. Make sure to prevent a paywall from being accessed after a purchase has occurred.

If a user purchases from a paywall, it is your responsibility to make sure that the user can’t access that paywall again. For example, if after successful purchase you decide to push a new view on to the navigation stack, you should make sure that the user can’t go back to access the paywall.

  1. Make sure the paywall view controller deallocates before presenting it elsewhere.

If you have a paywall view controller presented somewhere and you try to present the same view controller elsewhere, you will get a crash. For example, you may have a paywall in a tab bar controller, and then you also try to present it modally. We plan on improving this, but currently it’s your responsibility to ensure this doesn’t happen.

  1. Listening for Loading State Changes.

If you have logic that depends on the progress of the paywall’s loading state, you can use the delegate function paywall(_:loadingStateDidChange). Or, if you have an instance of a PaywallViewController, you can use the published property on iOS:

let stateSub = paywall.$loadingState.sink { state in
  print(state)
}