From 87865571c1331ceb47ca1bd64a2d22a15b563fac Mon Sep 17 00:00:00 2001 From: Trey t Date: Fri, 23 Dec 2022 11:51:22 -0600 Subject: [PATCH] iap work --- Shared/IAPManager.swift | 13 ++++++++++ Shared/views/PurchaseButtonView.swift | 12 ++++++--- Shared/views/SettingsView/SettingsView.swift | 26 ++++++++++++++++---- en.lproj/Localizable.strings | 1 + 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Shared/IAPManager.swift b/Shared/IAPManager.swift index ef31986..ff3c769 100644 --- a/Shared/IAPManager.swift +++ b/Shared/IAPManager.swift @@ -143,6 +143,11 @@ class IAPManager: ObservableObject { public func updateEverything() { Task { + DispatchQueue.main.async { + self.subscriptions.removeAll() + self.purchasedProductIDs.removeAll() + } + // get current sub from local cache await updatePurchasedProducts() @@ -365,6 +370,14 @@ class IAPManager: ObservableObject { } } + public func restore() async { + do { + try await AppStore.sync() + } catch { + print(error) + } + } + func checkVerified(_ result: VerificationResult) throws -> T { //Check whether the JWS passes StoreKit verification. switch result { diff --git a/Shared/views/PurchaseButtonView.swift b/Shared/views/PurchaseButtonView.swift index b0d0da2..f96e488 100644 --- a/Shared/views/PurchaseButtonView.swift +++ b/Shared/views/PurchaseButtonView.swift @@ -28,11 +28,15 @@ struct PurchaseButtonView: View { var body: some View { ZStack { - switch iapManager.showIAP { + // if we should show the iap warning that means no purchase which means + // we should show buy options + switch iapManager.showIAPWarning { case true: - buyOptionsView - .frame(height: CGFloat(height)) - .background(theme.currentTheme.secondaryBGColor) + VStack { + buyOptionsView + .frame(height: CGFloat(height)) + .background(theme.currentTheme.secondaryBGColor) + } case false: subscribedView .frame(height: CGFloat(height)) diff --git a/Shared/views/SettingsView/SettingsView.swift b/Shared/views/SettingsView/SettingsView.swift index 440b64a..84bff38 100644 --- a/Shared/views/SettingsView/SettingsView.swift +++ b/Shared/views/SettingsView/SettingsView.swift @@ -146,12 +146,26 @@ struct SettingsView: View { private var subscriptionInfoView: some View { ZStack { theme.currentTheme.secondaryBGColor - PurchaseButtonView(height: iapManager.currentSubscription != nil ? 300 : 200, iapManager: iapManager, showManageSubClosure: { - Task { - await - self.showManageSubscription() + VStack { + PurchaseButtonView(height: iapManager.currentSubscription != nil ? 300 : 200, iapManager: iapManager, showManageSubClosure: { + Task { + await + self.showManageSubscription() + } + }, showCountdownTimer: true) + + if iapManager.showIAPWarning { + Button(action: { + Task { + await iapManager.restore() + } + }, label: { + Text(String(localized: "purchase_view_restore")) + .font(.title3) + .padding([.top, .bottom]) + }) } - }, showCountdownTimer: true) + } } .cornerRadius(Constants.viewsCornerRaidus, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) } @@ -228,6 +242,7 @@ struct SettingsView: View { tmpDate = Calendar.current.date(byAdding: .minute, value: -59, to: tmpDate)! tmpDate = Calendar.current.date(byAdding: .second, value: -45, to: tmpDate)! firstLaunchDate = tmpDate + iapManager.updateEverything() }, label: { Text("Set first launch date back 29 days, 23 hrs, 45 seconds") .foregroundColor(textColor) @@ -243,6 +258,7 @@ struct SettingsView: View { theme.currentTheme.secondaryBGColor Button(action: { firstLaunchDate = Date() + iapManager.updateEverything() }, label: { Text("Reset luanch date to current date") .foregroundColor(textColor) diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index 48a74db..b6af793 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -115,6 +115,7 @@ "purchase_view_current_subscription_expires_in" = "Trial expires in:"; "purchase_view_current_subscription_expired_on" = "Trial expired on:"; "purchase_view_loading" = "Loading subscription options"; +"purchase_view_restore" = "Restore"; "iap_warning_view_title" = "This view will no longer scroll in "; "iap_warning_view_buy_button" = "Subscribe Now";