# getPaywall()

A function that retrieves a PaywallViewController for custom presentation.

> **Warning**

You're responsible for ensuring the returned `PaywallViewController` is no longer presented or embedded in a view after the user has moved past the paywall. The app may crash if you or the SDK attempts to present the same `PaywallViewController` instance again from elsewhere. Be especially careful when mixing `register()` and `getPaywall()`, which is not recommended.



> **Note**

The remotely configured presentation style is ignored when using this method. You must handle presentation styling programmatically.



Purpose [#purpose]

Retrieves a PaywallViewController that you can present however you want, bypassing Superwall's automatic presentation logic.

Signature [#signature]

```swift
// Async/await version
@MainActor
public func getPaywall(
  forPlacement placement: String,
  params: [String: Any]? = nil,
  paywallOverrides: PaywallOverrides? = nil,
  delegate: PaywallViewControllerDelegate,
  onCustomCallback: ((CustomCallback) async -> CustomCallbackResult)? = nil
) async throws -> PaywallViewController

// Completion handler version
public func getPaywall(
  forPlacement placement: String,
  params: [String: Any]? = nil,
  paywallOverrides: PaywallOverrides? = nil,
  delegate: PaywallViewControllerDelegate,
  onCustomCallback: ((CustomCallback) async -> CustomCallbackResult)? = nil,
  completion: @escaping (PaywallViewController?, PaywallSkippedReason?, Error?) -> Void
)
```

Parameters [#parameters]

<TypeTable
  type="{
  placement: {
    type: &#x22;String&#x22;,
    description: &#x22;The name of the placement as defined on the Superwall dashboard.&#x22;,
    required: true,
  },
  params: {
    type: &#x22;[String: Any]?&#x22;,
    description: &#x22;Optional parameters to pass with your placement for audience filters. Keys beginning with `$` are reserved and will be dropped.&#x22;,
    default: &#x22;nil&#x22;,
  },
  paywallOverrides: {
    type: &#x22;PaywallOverrides?&#x22;,
    description: &#x22;Optional overrides for products and presentation style.&#x22;,
    default: &#x22;nil&#x22;,
  },
  delegate: {
    type: &#x22;PaywallViewControllerDelegate&#x22;,
    description: &#x22;A delegate to handle user interactions with the retrieved PaywallViewController.&#x22;,
    required: true,
  },
  onCustomCallback: {
    type: &#x22;((CustomCallback) async -> CustomCallbackResult)?&#x22;,
    description: &#x22;Optional async handler called when the paywall requests a custom callback. Return a `CustomCallbackResult` to report success or failure back to the paywall. Available in version 4.15.1+.&#x22;,
    default: &#x22;nil&#x22;,
  },
  completion: {
    type: &#x22;@escaping (PaywallViewController?, PaywallSkippedReason?, Error?) -> Void&#x22;,
    description: &#x22;Completion block for the callback version.&#x22;,
    required: true,
  },
}"
/>

Returns / State [#returns--state]

Returns a `PaywallViewController` that you can present. If presentation should be skipped, throws a `PaywallSkippedReason` error.

Usage [#usage]

Using async/await:

```swift
Task {
  do {
    let paywallViewController = try await Superwall.shared.getPaywall(
      forPlacement: "premium_feature",
      params: ["source": "settings"],
      delegate: self,
      onCustomCallback: { callback in
        switch callback.name {
        case "validate_email":
          return .success(data: ["validated": true])
        default:
          return .failure()
        }
      }
    )
    
    present(paywallViewController, animated: true)
  } catch let reason as PaywallSkippedReason {
    print("Paywall skipped: \(reason)")
  } catch {
    print("Error getting paywall: \(error)")
  }
}
```

Using completion handler:

```swift
Superwall.shared.getPaywall(
  forPlacement: "premium_feature",
  delegate: self,
  onCustomCallback: { callback in
    .success(data: ["callback": callback.name])
  }
) { paywall, skippedReason, error in
  if let paywall = paywall {
    present(paywall, animated: true)
  } else if let reason = skippedReason {
    print("Paywall skipped: \(reason)")
  } else if let error = error {
    print("Error: \(error)")
  }
}
```