Skip to content

Commit

Permalink
Retrieve product ids with active subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Tikhonenko committed Oct 11, 2021
1 parent 172f3fe commit b0f1a88
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Sources/Mercato/Mercato.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = []

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<T>(_ result: VerificationResult<T>) throws -> T
{
switch result
Expand Down

0 comments on commit b0f1a88

Please sign in to comment.