Skip to main content
Question

PaywallView initialization with `purchasesAreCompletedBy` set to `.myApp`


Forum|alt.badge.img
  • New Member
  • 1 reply

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?

This post has been closed for comments

2 replies

chris_perriam
RevenueCat Staff
Forum|alt.badge.img+4

Hi ​@bob_  in this case, the paywall needs to linked with your app’s purchase logic so that the correct implementation for purchases and restores is invoked when the relevant paywall actions are made by the user.

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 [option + 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
            )
        })
    }
}

 


Forum|alt.badge.img
  • Author
  • New Member
  • 1 reply
  • May 30, 2025

Thanks, Chris! That’s very helpful and close to what I implemented.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings