Reload receipt on purchase (#892)

StoreKit ProductView performs the purchases internally without calling
IAPManager.purchase(), which causes the IAPManager state to be
momentarily outdated.

Leverage PaywallView.onComplete() to reload the receipt and eventually
trigger IAPManager.objectWillChange, so that the app is immediately
unlocked on a successful purchase.
This commit is contained in:
Davide 2024-11-19 11:36:36 +01:00 committed by GitHub
parent bac1d494a4
commit 35c10309a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 4 deletions

View File

@ -48,7 +48,7 @@ struct InstalledProfileView: View, Routable {
@Binding @Binding
var nextProfileId: Profile.ID? var nextProfileId: Profile.ID?
var flow: ProfileContainerView.Flow? var flow: ProfileFlow?
var body: some View { var body: some View {
debugChanges() debugChanges()

View File

@ -109,7 +109,7 @@ private struct ContainerModifier: ViewModifier {
@ObservedObject @ObservedObject
var profileManager: ProfileManager var profileManager: ProfileManager
let flow: ProfileContainerView.Flow? let flow: ProfileFlow?
@State @State
private var search = "" private var search = ""

View File

@ -43,7 +43,7 @@ struct ProfileGridView: View, Routable, TunnelInstallationProviding {
let errorHandler: ErrorHandler let errorHandler: ErrorHandler
var flow: ProfileContainerView.Flow? var flow: ProfileFlow?
@State @State
private var nextProfileId: Profile.ID? private var nextProfileId: Profile.ID?

View File

@ -49,7 +49,7 @@ struct ProfileListView: View, Routable, TunnelInstallationProviding {
let errorHandler: ErrorHandler let errorHandler: ErrorHandler
var flow: ProfileContainerView.Flow? var flow: ProfileFlow?
@State @State
private var nextProfileId: Profile.ID? private var nextProfileId: Profile.ID?

View File

@ -224,6 +224,9 @@ private extension PaywallView {
func onComplete(_ productIdentifier: String, result: InAppPurchaseResult) { func onComplete(_ productIdentifier: String, result: InAppPurchaseResult) {
switch result { switch result {
case .done: case .done:
Task {
await iapManager.reloadReceipt()
}
isPresented = false isPresented = false
case .pending: case .pending: