The sample app is pretty light when it comes to restoring purchases:
Button("Restore Purchases") {
Task {
try? await Purchases.shared.restorePurchases()
}
}
There are 3 possible outcomes when it comes to a subscription:
- Success
- Failure due to lack of active subscription
- Error
I want to be able to show an alert of sorts in all 3 cases.
My view has two variables:
@Environment(\.isPremium) var isPremium
@EnvironmentObject var customer: Customer
Where customer is Purchases’ delegate and has the CustomerInfo
and isPremium derives its value from that customer, an @ObservedObject of my app:
.environment(\.isPremium, customer.isPremium)
The button to restore looks like this.
Button(action: {
isRestoringPurchase = true
Task {
do {
let _ = try await Purchases.shared.restorePurchases()
} catch {
// Inform user of error
}
// Inform user of result based on customer.isPremium
isRestoringPurchase = false
}
})
This works fine: restorePurchases() calls its delegate (which is and customer is updated by the time I use it to inform the user.
But, if I use the env var isPremium instead of customer.isPremium, its value is not updated in time to inform the user, but only shortly after.
Two questions:
1. why the lag? It feels like it’s just a matter of one cycle being missed.
2. is there another way to approach this?