The sample app is pretty light when it comes to restoring purchases:
1 Button("Restore Purchases") {2 Task {3 try? await Purchases.shared.restorePurchases()4 }5 }
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:
1@Environment(\.isPremium) var isPremium2@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:
1.environment(\.isPremium, customer.isPremium)
The button to restore looks like this.
1 Button(action: {2 isRestoringPurchase = true3 Task {4 do {5 let _ = try await Purchases.shared.restorePurchases()6 } catch {7 // Inform user of error8 }9 // Inform user of result based on customer.isPremium10 isRestoringPurchase = false11 }12 })
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?