diff --git a/CHANGELOG.md b/CHANGELOG.md index 49afefc..c68887a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 0.1.3 (2024-10-31) +* Verified transactions updated from outside the app are now added to purchasedProductIds. + ## 0.1.2 (2024-10-18) * Better use of async context, `fetchAndSync()` significantly faster as a result. * Improve documentation and examples in README.md diff --git a/Sources/StoreKitHelper/PurchaseHelper.swift b/Sources/StoreKitHelper/PurchaseHelper.swift index 2dd1ff1..b92c208 100644 --- a/Sources/StoreKitHelper/PurchaseHelper.swift +++ b/Sources/StoreKitHelper/PurchaseHelper.swift @@ -42,8 +42,15 @@ public class PurchaseHelper: ObservableObject { self.storeKitCommunicator = StoreKitCommunicator(autoFinishTransactions: autoFinishTransactions) Task { - // result can be ignored, we just wanted to finish the transaction - let _ = await storeKitCommunicator.listenForTransactionUpdatesAsync() + // listen for updates outside of the app + for productId in await storeKitCommunicator.listenForTransactionUpdatesAsync() { + updateUI { [weak self] in + guard let self else { return } + if !self.purchasedProductIds.contains(productId) { + self.purchasedProductIds.append(productId) + } + } + } } } diff --git a/Sources/StoreKitHelper/StoreKitCommunicator.swift b/Sources/StoreKitHelper/StoreKitCommunicator.swift index 0ef8e75..aceaaa0 100644 --- a/Sources/StoreKitHelper/StoreKitCommunicator.swift +++ b/Sources/StoreKitHelper/StoreKitCommunicator.swift @@ -72,16 +72,17 @@ final internal class StoreKitCommunicator: Sendable { } } - func listenForTransactionUpdatesAsync() async -> String? { + func listenForTransactionUpdatesAsync() async -> [String] { + var verifiedProductIdsOutsideTheApp: [String] = [] for await result in Transaction.updates { if case .verified(let transaction) = result { print("PurchaseHelper transaction updated outside the app: \(transaction.productID)") if autoFinishTransactions { await transaction.finish() } - return transaction.productID + verifiedProductIdsOutsideTheApp.append(transaction.productID) } } - return nil + return verifiedProductIdsOutsideTheApp } }