diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 15f8511..c96ddd3 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,12 @@ # Release notes +## 0.3.1 + +This version fixes an async error that could cause purchases to update the context on a background thread. + + + ## 0.3 StoreKitPlus now uses Swift 5.9, which requires Xcode 15. diff --git a/Sources/StoreKitPlus/Services/StandardStorePurchaseService.swift b/Sources/StoreKitPlus/Services/StandardStorePurchaseService.swift index 574c1d4..d82bc6d 100644 --- a/Sources/StoreKitPlus/Services/StandardStorePurchaseService.swift +++ b/Sources/StoreKitPlus/Services/StandardStorePurchaseService.swift @@ -38,7 +38,9 @@ open class StandardStorePurchaseService: StorePurchaseService { private let context: StoreContext private var transactionTask: Task? - open func purchase(_ product: Product) async throws -> Product.PurchaseResult { + open func purchase( + _ product: Product + ) async throws -> Product.PurchaseResult { #if os(visionOS) throw StoreServiceError.unsupportedPlatform("This purchase operation is not supported in visionOS: Use @Environment(\\.purchase) instead.") #else @@ -114,10 +116,12 @@ private extension StandardStorePurchaseService { var transactions = context.purchaseTransactions .filter { $0.productID != transaction.productID } transactions.append(transaction) - context.purchaseTransactions = transactions + updateContext(with: transactions) } func updateContext(with transactions: [Transaction]) { - context.purchaseTransactions = transactions + DispatchQueue.main.async { + self.context.purchaseTransactions = transactions + } } }