Skip to content

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
mvojtkovszky committed Oct 31, 2024
2 parents c61a8a5 + 5859d89 commit 6f552ff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 9 additions & 2 deletions Sources/StoreKitHelper/PurchaseHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/StoreKitHelper/StoreKitCommunicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 6f552ff

Please sign in to comment.