Retrieving and Presenting a Paywall Yourself
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. The following is code is how you’d mimic register:
This does the following:
- Gets the paywall view controller.
- Handles the cases where the paywall was skipped.
- Catches any presentation errors.
- 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 theresult
depending on how you first presented your view. Then, it switches over theresult
. If the result ispurchased
orrestored
the feature can be launched. However, if the result isdeclined
, it checks that the thefeatureGating
property ofpaywall.info
isnonGated
and that thecloseReason
isn’t.forNextPaywall
.
Best practices
- 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.
- 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.