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