minor improvements to Guard

sync3
Laurent 2 months ago
parent 9ed8e56c2e
commit e3b3c6456c
  1. 45
      PadelClubData/Subscriptions/Guard.swift

@ -30,11 +30,7 @@ import Combine
self.updateListenerTask = self.listenForTransactions()
Task {
do {
try await self.refreshPurchasedAppleProducts()
} catch {
Logger.error(error)
}
await self.refreshPurchases()
Logger.log("plan = \(String(describing: currentBestPurchase?.productId))")
}
@ -66,19 +62,46 @@ import Combine
return productIds
}
public func refreshPurchasedAppleProducts() async throws {
public func refreshPurchases() async {
await _refreshUnfinishedTransactions()
await _refreshPurchasedAppleProducts()
}
fileprivate func _refreshPurchasedAppleProducts() async {
// Iterate through the user's purchased products.
for await verificationResult in Transaction.currentEntitlements {
let transaction = try await self.processTransactionResult(verificationResult)
print("processs product id = \(transaction.productID)")
DispatchQueue.main.async {
NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil)
do {
let transaction = try await self.processTransactionResult(verificationResult)
print("processs product id = \(transaction.productID)")
DispatchQueue.main.async {
NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil)
}
await transaction.finish()
} catch {
Logger.error(error)
}
await transaction.finish()
}
}
public func _refreshUnfinishedTransactions() async {
// Iterate through the user's purchased products.
for await verificationResult in Transaction.unfinished {
do {
let transaction = try await self.processTransactionResult(verificationResult)
print("processs product id = \(transaction.productID)")
DispatchQueue.main.async {
NotificationCenter.default.post(name: Notification.Name.StoreEventHappened, object: nil)
}
await transaction.finish()
} catch {
Logger.error(error)
}
}
}
func listenForTransactions() -> Task<Void, Never> {
return Task(priority: .background) {
//Iterate through any transactions which didn't come from a direct call to `purchase()`.

Loading…
Cancel
Save