Superwall

subscriptionStatus

A published property that indicates the subscription status of the user.

If you're using a custom PurchaseController, you must update this property whenever the user's entitlements change.

You can also observe changes via the SuperwallDelegate method subscriptionStatusDidChange(from:to:).

Purpose

Indicates the current subscription status of the user and can be observed for changes using Combine or SwiftUI.

Signature

@Published
public var subscriptionStatus: SubscriptionStatus { get set }

Parameters

This property accepts a SubscriptionStatus enum value:

  • .unknown - Status is not yet determined
  • .active(Set<Entitlement>) - User has active entitlements (set of entitlement identifiers)
  • .inactive - User has no active entitlements

Returns / State

Returns the current SubscriptionStatus. When using a PurchaseController, you must set this property yourself. Otherwise, Superwall manages it automatically.

Usage

Set subscription status (when using PurchaseController):

Superwall.shared.subscriptionStatus = .active(["premium", "pro_features"])
Superwall.shared.subscriptionStatus = .inactive

Get current subscription status:

let status = Superwall.shared.subscriptionStatus
switch status {
case .unknown:
  print("Subscription status unknown")
case .active(let entitlements):
  print("User has active entitlements: \(entitlements)")
case .inactive:
  print("User has no active subscription")
}

Observe changes with Combine:

import Combine

class ViewController: UIViewController {
  private var cancellables = Set<AnyCancellable>()
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    Superwall.shared.$subscriptionStatus
      .sink { [weak self] status in
        self?.updateUI(for: status)
      }
      .store(in: &cancellables)
  }
  
  func updateUI(for status: SubscriptionStatus) {
    switch status {
    case .active:
      showPremiumContent()
    case .inactive:
      showFreeContent()
    case .unknown:
      showLoadingState()
    }
  }
}

SwiftUI observation:

struct ContentView: View {
  @StateObject var superwall = Superwall.shared
  
  var body: some View {
    VStack {
      switch superwall.subscriptionStatus {
      case .active(let entitlements):
        Text("Premium user with: \(entitlements.joined(separator: ", "))")
      case .inactive:
        Text("Free user")
      case .unknown:
        Text("Loading...")
      }
    }
  }
}

How is this guide?

On this page