Skip to content

Commit

Permalink
Wrap method into IAPHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniele Bogo authored and Daniele Bogo committed Nov 25, 2024
1 parent 85131bd commit b08f8ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 1 addition & 8 deletions podcasts/CancelConfirmationViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SwiftUI
import PocketCastsServer
import PocketCastsUtils
import StoreKit

class CancelConfirmationViewModel: OnboardingModel {
let navigationController: UINavigationController
Expand Down Expand Up @@ -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()

Expand Down
10 changes: 10 additions & 0 deletions podcasts/IAPHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down

0 comments on commit b08f8ed

Please sign in to comment.