From 51cc7ec0fe7347d4cb92c00f9566d289f276d64c Mon Sep 17 00:00:00 2001 From: Pavel Tikhonenko Date: Wed, 11 May 2022 22:11:24 +0200 Subject: [PATCH] Add extra method for retrieving active subscriptions --- Sources/Mercato/Mercato.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/Mercato/Mercato.swift b/Sources/Mercato/Mercato.swift index e4f0a08..7c01a43 100644 --- a/Sources/Mercato/Mercato.swift +++ b/Sources/Mercato/Mercato.swift @@ -136,9 +136,9 @@ extension Mercato try await AppStore.showManageSubscriptions(in: scene) } - public static func activeSubscriptions(onlyRenewable: Bool = true) async throws -> [String] + public static func activeSubscriptions(onlyRenewable: Bool = true) async throws -> [Transaction] { - var productIds: Set = [] + var txs: [Transaction] = [] for await result in Transaction.currentEntitlements { @@ -148,15 +148,20 @@ extension Mercato if transaction.productType == .autoRenewable || (!onlyRenewable && transaction.productType == .nonRenewable) { - productIds.insert(transaction.productID) + txs.append(transaction) } } catch { throw error } } - return Array(productIds) + return Array(txs) } + + public static func activeSubscriptionIds(onlyRenewable: Bool = true) async throws -> [String] + { + return try await activeSubscriptions(onlyRenewable: onlyRenewable).map { $0.productID} + } }