Display a paywall
Resolve the paywall assigned to a location and present it from your app.
Use this page to show a hosted paywall from the Swift SDK. A paywall is the screen a customer
sees. A location is the stable slug your app asks for, such as onboarding or
settings-upsell. You publish paywalls and assign them to locations in Studio, as described in
Paywall locations.
Present it
Ask for a location, and the SDK presents whichever paywall is assigned to it.
let result = try await voidhash.presentPaywall(
location: "settings-upsell",
delegate: paywallsDelegate
)presentPaywall resolves the paywall configured for the location and presents it fullscreen. It
speaks the paywall bridge protocol natively, so purchases, restores, close, and external links are
handled for you.
The result tells you what happened:
.shown: the presenter opened the paywall..notAssigned: no published paywall is assigned to the location..failed: resolving or presenting the paywall failed.
Pass a delegate to be told about purchases and dismissal.
final class Paywalls: VoidhashPaywallDelegate {
func paywall(_ location: String, didPurchaseProductId productId: String, requestId: String?) {}
func paywallDidDismiss(_ location: String) {}
}Every delegate method has a default no-op implementation, so you only implement the ones you need. The SDK holds the delegate weakly. Keep your own strong reference for as long as the paywall is presented, because a released delegate silently stops receiving callbacks.
You can also close the paywall from your own code.
try await voidhash.dismissPaywall()Purchases and restores started from a hosted paywall go through the same purchase pipeline as any other purchase. After a successful transaction, Voidhash refreshes the person snapshot and dismisses the paywall.
Fall back when nothing was shown
When you clear or archive a location in Studio, later presentations return .notAssigned. Keep a
fallback for important entry points so the customer still has a way to upgrade.
let result = try await voidhash.presentPaywall(location: "settings-upsell")
if result != .shown {
showOwnUpgradeScreen()
}