diff --git a/Sources/Mercato/Mercato.swift b/Sources/Mercato/Mercato.swift index 8bc2633..e4f0a08 100644 --- a/Sources/Mercato/Mercato.swift +++ b/Sources/Mercato/Mercato.swift @@ -135,8 +135,31 @@ extension Mercato { try await AppStore.showManageSubscriptions(in: scene) } + + public static func activeSubscriptions(onlyRenewable: Bool = true) async throws -> [String] + { + var productIds: Set = [] + + for await result in Transaction.currentEntitlements + { + do { + let transaction = try checkVerified(result) + + if transaction.productType == .autoRenewable || + (!onlyRenewable && transaction.productType == .nonRenewable) + { + productIds.insert(transaction.productID) + } + } catch { + throw error + } + } + + return Array(productIds) + } } + func checkVerified(_ result: VerificationResult) throws -> T { switch result