Hi folks.
I already have internal purchase logic in my app, and I’m trying to implement RevenueCat’s PaywallView to do A/B testing.
My PaywallView presents this message: PaywallView has not been correctly initialized. purchasesAreCompletedBy is set to .myApp, and so the PaywallView must be initialized with a PerformPurchase and PerformRestore handler.
Is there documentation on this requirement?
Hi
We’re working on improving the online documentation for the RevenueCatUI package, but in the interim I’d recommend checking out Xcode’s Developer Documentation which should source relevant docs from the RevenueCat source code. You can access this by eoption + click] on types such as PaywallView
.
Here is a very basic example of how performPurchase
and performRestore
can be used:
struct ContentView: View {
@State var paywallPresented = false
@MainActor
func performPurchase(_ packageToPurchase: Package) async -> (userCancelled: Bool, error: Error?) {
do {
// Your app's purchase logic here
return (userCancelled: false, error: nil)
} catch {
return (userCancelled: false, error: error)
}
}
@MainActor
func performRestore() async -> (success: Bool, error: Error?) {
do {
// Your app's restore logic here
return (success: true, error: nil)
} catch {
return (success: false, error: error)
}
}
var body: some View {
VStack {
Button("Display Paywall") {
self.paywallPresented = true
}
}
.sheet(isPresented: $paywallPresented, content: {
PaywallView(
performPurchase: performPurchase,
performRestore: performRestore
)
})
}
}
Thanks, Chris! That’s very helpful and close to what I implemented.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.