From b08f8ed6d78425e7ac6d312dca5ecd1c2840cda1 Mon Sep 17 00:00:00 2001 From: Daniele Bogo Date: Mon, 25 Nov 2024 16:56:42 +0000 Subject: [PATCH] Wrap method into IAPHelper --- podcasts/CancelConfirmationViewModel.swift | 9 +-------- podcasts/IAPHelper.swift | 10 ++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/podcasts/CancelConfirmationViewModel.swift b/podcasts/CancelConfirmationViewModel.swift index ae872f4abf..e4b97d0df3 100644 --- a/podcasts/CancelConfirmationViewModel.swift +++ b/podcasts/CancelConfirmationViewModel.swift @@ -1,7 +1,6 @@ import SwiftUI import PocketCastsServer import PocketCastsUtils -import StoreKit class CancelConfirmationViewModel: OnboardingModel { let navigationController: UINavigationController @@ -32,13 +31,7 @@ class CancelConfirmationViewModel: OnboardingModel { return } do { - if let groupID = await IAPHelper.shared.findLastSubscriptionPurchasedGroupID(), #available(iOS 17.0, *) { - FileLog.shared.console("[CancelConfirmationViewModel] Last subscription purchased group ID: \(groupID)") - - try await StoreKit.AppStore.showManageSubscriptions(in: windowScene, subscriptionGroupID: groupID) - } else { - try await StoreKit.AppStore.showManageSubscriptions(in: windowScene) - } + try await IAPHelper.shared.showManageSubscriptions(in: windowScene) await ApiServerHandler.shared.retrieveSubscriptionStatus() diff --git a/podcasts/IAPHelper.swift b/podcasts/IAPHelper.swift index ea963110f4..06ec7d060e 100644 --- a/podcasts/IAPHelper.swift +++ b/podcasts/IAPHelper.swift @@ -109,6 +109,16 @@ class IAPHelper: NSObject { .first?.subscriptionGroupID } + func showManageSubscriptions(in windowScene: UIWindowScene) async throws { + if let groupID = await findLastSubscriptionPurchasedGroupID(), #available(iOS 17.0, *) { + FileLog.shared.console("[CancelConfirmationViewModel] Last subscription purchased group ID: \(groupID)") + + try await StoreKit.AppStore.showManageSubscriptions(in: windowScene, subscriptionGroupID: groupID) + } else { + try await StoreKit.AppStore.showManageSubscriptions(in: windowScene) + } + } + /// Whether the products have been loaded from StoreKit var hasLoadedProducts: Bool { productsArray.count > 0 }