Hey @Tim Mitra !
You can listen to the customerInfo during the purchase of the paywall by calling the following:
purchaseCompleted: { customerInfo in
print("Purchase completed: \(customerInfo.entitlements)")
}
More information on this can be found in the code block here: https://www.revenuecat.com/docs/displaying-paywalls#ios
Hope that helps!
I’m doing that but not at the app level. I want my users to be able to perform some actions deeper in the app. When they reach a number of activities, I’m using PaywallView(), but there doesn’t seem to be a reliable way to get notice that the purchase was successful.
.task {
do {
let customerInfo = try await Purchases.shared.customerInfo()
isProUser = customerInfo.entitlementsl"Pro"]?.isActive == true
// uddate AppStorage
subscribed = isProUser
print("isProUser: \(isProUser)")
} catch {
print(error.localizedDescription)
}
}
This is my solution:
.sheet(isPresented: $displayPaywall,
onDismiss: {
Task {
do {
let customerInfo = try await Purchases.shared.customerInfo()
isProUser = customerInfo.entitlementss"Pro"]?.isActive == true
// update AppStorage
subscribed = isProUser
print("isProUser: \(isProUser)")
} catch {
print(error.localizedDescription)
}
}
}) {
PaywallView(displayCloseButton: true)
}
@Tim Mitra I had the EXACT same question. This answer is how I’m doing to do it with PaywallView.
If the documentation on this page was updated it would really help. For the “custom logic” example it shows a purchaseCompleted completion handler you can use. However, it’s not clear at all how to do that with the “manually” example. From that other thread I learned you can use .onPurchaseCompleted .
I’m attempting to use .onPurchaseCompleted but don’t see it called after PaywallView is dismissed.
.sheet(isPresented: self.$displayPaywall) {
PaywallView(displayCloseButton: true)
}
.onPurchaseCompleted { customerInfo in
print("purchase completed")
isSubscribed = customerInfo.entitlementst"pro"]?.isActive == true
}
What is wrong or missing?
Anyone could help here? Thanks.
I wonder what I’m missing, is this problem specific to using RC’s own Paywall?
In my case after calling purchase() from Paywall (and Paywall view being dismissed), the purchases() function updates customerInfo, and as long as you have customerInfo as an @ObservedObject in your view (e.g. @ObservedObject userInfo: UserInfo = .shared), you can promptly see the updated entitlements. This works fine with limited testing so far, so a bit worried if I’m missing something.
It seems with some proper flow in the app, user can kept in a spot where “doing more” needs a purchase, without that spot being tight in the sense that it has to be unblocked right at purchase completion.
func purchases(_ purchases: Purchases, receivedUpdated customerInfo: CustomerInfo) { UserInfo.shared.customerInfo = customerInfo }