Question

SwiftUI, show paywall based on offering and entitlement ids?

  • 15 December 2023
  • 1 reply
  • 83 views

Badge +2

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: []))


1 reply

Userlevel 5
Badge +8

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)
}
}

 

Reply