Use a Superwall’s delegate to extend our SDK’s functionality across several surface areas by assigning to the delegate property:

class SWDelegate: SuperwallDelegate {
    // Implement delegate methods here
}

// After configuring the SDK...
Superwall.shared.delegate = SWDelegate()

Some common use cases for using the Superwall delegate include:

Below are some commonly used implementations when using the delegate.

Superwall Placements

Most of what occurs in Superwall can be viewed using the delegate method to respond to placements:

class SWDelegate: SuperwallDelegate {
  func handleSuperwallPlacement(withInfo placementInfo: SuperwallPlacementInfo) {
    switch placementInfo.placement {
    case .transactionComplete(let transaction, let product, let paywallInfo):
      print("Converted from paywall originalTransactionIdentifier: \(transaction?.originalTransactionIdentifier ?? "")")
      print("Converted from paywall storeTransactionId: \(transaction?.storeTransactionId ?? "")")
      print("Converted from paywall productIdentifier: \(product.productIdentifier)")
      print("Converted from paywall paywallInfo: \(paywallInfo.identifier)")
    case .transactionRestore(let restoreType, let paywallInfo):
      print("transactionRestore restoreType \(restoreType)")
    case let .customPlacement(name, params, paywallInfo):
      // Forward Mixpanel/Ampltiude/etc
      print("\(name) - \(params) - \(paywallInfo)")
    default:
      // And several more placements to use...
      print("Default placement: \(placementInfo.placement.description)")
    }
  }
}

Paywall Custom Actions

Using the custom tap action, you can respond to any arbitrary event from a paywall:

class SWDelegate: SuperwallDelegate {
  func handleCustomPaywallAction(withName name: String) {
    if name == "showHelpCenter" {
      DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
        self.showHelpCenter.toggle()
      }
    }
  }
}

Subscription status changes

You can be informed of subscription status changes using the delegate. If you need to set or handle the status on your own, use a purchase controller — this function is only for informational, tracking or similar purposes:

class SWDelegate: SuperwallDelegate {
  func subscriptionStatusDidChange(from oldValue: SubscriptionStatus, to newValue: SubscriptionStatus) {
    // Log or handle subscription change in your Ui
  }
}

Paywall events

The delegate also has callbacks for several paywall events, such dismissing, presenting, and more. Here’s an example:

class SWDelegate: SuperwallDelegate {
  func didPresentPaywall(withInfo paywallInfo: PaywallInfo) {
    // paywallInfo will contain all of the presented paywall's info
  }
}