Paywall preloading

In order to speed up the display of the view controller you may decide to preload it and use use later in your application.

Depending on your application you may want to preload it when the application start or when the main view controller start.

In the following example code we provide two function to help with the preloading :

  1. preloadPaywall that should be called as soon as your possibile in the life of your viewcontroller/application
  2. nowDisplayThePaywall that should be called when you want to actually display the paywall to your user

This code is an example and should be adapted to your use case.

After the purchase is completed or cancelled the setCloseHandler is called with information about the transaction.
You may also find useful to referece the Verify Subscription Status documentation.

import Glassfy
import UIKit

class ViewController: UIViewController {
    var paywallToDisplay: Glassfy.PaywallViewController? = nil;

    func preloadPaywall() {
        Glassfy.paywall(id: "mypaywall") { newPaywall, _ in
            
            self.paywallToDisplay = newPaywall
        }
    }
    
    func nowDisplayThePaywall() {
        if let paywallToDisplay = paywallToDisplay {
            
            paywallToDisplay.setCloseHandler { transaction, error in
                // handle the transaction
                // this is the transaction https://docs.glassfy.io/docs/transaction
                // it contains a permissions that https://docs.glassfy.io/docs/permissions
                // you can reference the code here for verifying the permissions:
                // https://docs.glassfy.io/docs/verify-subscription-status
            }
            
            self.present(paywallToDisplay, animated: true, completion: nil)
        }
    }
}