Skip to main content
Question

SwiftUI, show paywall based on offering and entitlement ids?

  • December 15, 2023
  • 1 reply
  • 474 views

Forum|alt.badge.img+3

I have two subscriptions and two RevenueCat paywalls are attached for each subscription. Now i want to show the paywall for each product in my .sheet () modifier passing the entitlement and offerings in SwiftUI.

can i do achieve through this

.presentPaywallIfNeeded(requiredEntitlementIdentifier: "", offering: Offering(identifier: "", serverDescription: "", availablePackages: []))

This post has been closed for comments

1 reply

Andy
RevenueCat Staff
Forum|alt.badge.img+8
  • RevenueCat Staff
  • December 18, 2023

You wouldn’t initialize the offering directly, but rather obtain it from the SDK, and then pass it in to the presentPaywallIfNeeded method. 

 

Something like 
 



// do this somewhere in your app. It could be a .task on the view, or it could be
// another class that is dedicated to interacting with the RevenueCat SDK.

do {
let offerings = try await Purchases.shared.offerings()
guard let offering1 = offerings["offering1"] else {
// handle error for missing offering, probably a configuration error in the dashboard
}

self.offering1 = offering1
} catch {
// handle errors when getting offerings
// this could be a connection error, misconfiguration, etc
}



// then in your view:

struct MyView: View {
var body: some View {
StuffThatGoesBehindPaywall()
.presentPaywallIfNeeded(requiredEntitlementIdentifier: "entitlement1", offering: self.offering1)
}
}