From 35c10309a7f832b9d915c1374dbd7de549c98786 Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 19 Nov 2024 11:36:36 +0100 Subject: [PATCH] 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. --- .../Sources/AppUIMain/Views/App/InstalledProfileView.swift | 2 +- .../Sources/AppUIMain/Views/App/ProfileContainerView.swift | 2 +- .../Library/Sources/AppUIMain/Views/App/ProfileGridView.swift | 2 +- .../Library/Sources/AppUIMain/Views/App/ProfileListView.swift | 2 +- .../Library/Sources/UILibrary/Views/Paywall/PaywallView.swift | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift index 3ba3bcfb..0c7420da 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/InstalledProfileView.swift @@ -48,7 +48,7 @@ struct InstalledProfileView: View, Routable { @Binding var nextProfileId: Profile.ID? - var flow: ProfileContainerView.Flow? + var flow: ProfileFlow? var body: some View { debugChanges() diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift index 672c7489..2f0b5749 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileContainerView.swift @@ -109,7 +109,7 @@ private struct ContainerModifier: ViewModifier { @ObservedObject var profileManager: ProfileManager - let flow: ProfileContainerView.Flow? + let flow: ProfileFlow? @State private var search = "" diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileGridView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileGridView.swift index 9a9275aa..575ee189 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileGridView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileGridView.swift @@ -43,7 +43,7 @@ struct ProfileGridView: View, Routable, TunnelInstallationProviding { let errorHandler: ErrorHandler - var flow: ProfileContainerView.Flow? + var flow: ProfileFlow? @State private var nextProfileId: Profile.ID? diff --git a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileListView.swift b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileListView.swift index 60aacbce..c9b707f3 100644 --- a/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileListView.swift +++ b/Passepartout/Library/Sources/AppUIMain/Views/App/ProfileListView.swift @@ -49,7 +49,7 @@ struct ProfileListView: View, Routable, TunnelInstallationProviding { let errorHandler: ErrorHandler - var flow: ProfileContainerView.Flow? + var flow: ProfileFlow? @State private var nextProfileId: Profile.ID? diff --git a/Passepartout/Library/Sources/UILibrary/Views/Paywall/PaywallView.swift b/Passepartout/Library/Sources/UILibrary/Views/Paywall/PaywallView.swift index a251b31d..fdbf1ba7 100644 --- a/Passepartout/Library/Sources/UILibrary/Views/Paywall/PaywallView.swift +++ b/Passepartout/Library/Sources/UILibrary/Views/Paywall/PaywallView.swift @@ -224,6 +224,9 @@ private extension PaywallView { func onComplete(_ productIdentifier: String, result: InAppPurchaseResult) { switch result { case .done: + Task { + await iapManager.reloadReceipt() + } isPresented = false case .pending: