.onPurchaseComplete


Badge +1

Hi. In my app I am calling the paywall when the user reaches more than a certain number of rows. Let's say 2. Then I present the paywall. After a successful purchase I have to close and re-open the app in order to trigger the valid subscription to allow more entries. How do I fix this inline at the time of the purchase. 

 

.sheet(isPresented: $isShowingPaywall) {

                            PaywallView()

                        }

Here is my save code where I trigger this.

 

func save() {

        let bgcolor = selectedColor.toHex() ?? "#FFFFFF"

        print("Before SubscriptionActive: \(userViewModel.isSubscriptionActive)")

        let isSubscriptionActive = userViewModel.isSubscriptionActive

       // print("AFter SubscriptionActive: \(userViewModel.isSubscriptionActive)")

      

        // Retrieve the total count from UserDefaults

        var totalCount = UserDefaults.standard.integer(forKey: "TotalCount")

      //  print("total count in beginning of save \(totalCount)")

        // Check if it's the first entry and there's no total count saved

        if data.isEmpty && totalCount == 0 {

            // Allow the save

        } else if !isSubscriptionActive && totalCount >= 3 && entryToEdit == nil {

            // Show the paywall

            isShowingPaywall = true

            return

        }

        

        if entryToEdit != nil {

            entryToEdit?.title = title

            entryToEdit?.reset = selectedResetOption.rawValue

            entryToEdit?.defaultcount = defaultcount

            entryToEdit?.locked = locked

            entryToEdit?.bgcolor = bgcolor

        } else {

            let data = dataclass(title: title,

                                 reset: selectedResetOption.rawValue,

                                 defaultcount: defaultcount,

                                 bgcolor: bgcolor,

                                 date: Date(),

                                 locked: locked

            )

            context.insert(data)

            totalCount += 1

            UserDefaults.standard.set(totalCount, forKey: "TotalCount")

        }

        dismiss()

    }

 


This post has been closed for comments

2 replies

Userlevel 1
Badge +4

Hi @bill-harned-e655d2! Just to confirm, you’re saying that after a successful purchase, the subscription is not unlocked for your customer? How are you setting this value `userViewModel.isSubscriptionActive`? You may want to fetch new CustomerInfo after the purchase and ensure the updated object is used in your viewmodel (docs). Let me know if that helps!

Badge +1

Thanks Jeffrey - I will revisit and see if I can figure out how to do that. (new developer here)