Skip to content

Commit

Permalink
StoreKit1Wrapper: added debug log when transaction is removed but n…
Browse files Browse the repository at this point in the history
…o callbacks to notify (#2418)

This would make issues like #2415 easier to debug.
  • Loading branch information
NachoSoto authored Apr 20, 2023
1 parent d71772c commit 4a90351
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions Sources/Logging/Strings/PurchaseStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ enum PurchaseStrings {
case finishing_transaction(StoreTransactionType)
case purchasing_with_observer_mode_and_finish_transactions_false_warning
case paymentqueue_revoked_entitlements_for_product_identifiers(productIdentifiers: [String])
case paymentqueue_removed_transaction(_ observer: SKPaymentTransactionObserver,
_ transaction: SKPaymentTransaction)
case paymentqueue_updated_transaction(_ observer: SKPaymentTransactionObserver,
_ transaction: SKPaymentTransaction)
case paymentqueue_removed_transaction(SKPaymentTransactionObserver,
SKPaymentTransaction)
case paymentqueue_removed_transaction_no_callbacks_found(SKPaymentTransactionObserver,
SKPaymentTransaction)
case paymentqueue_updated_transaction(SKPaymentTransactionObserver,
SKPaymentTransaction)
case presenting_code_redemption_sheet
case unable_to_present_redemption_sheet
case purchases_synced
Expand Down Expand Up @@ -131,6 +133,10 @@ extension PurchaseStrings: CustomStringConvertible {
.compactMap { $0 }
.joined(separator: " ")

case let .paymentqueue_removed_transaction_no_callbacks_found(observer, transaction):
return "\(observer.debugName) removedTransaction for (\(transaction.payment.productIdentifier) " +
"but not callbacks to notify"

case let .paymentqueue_updated_transaction(observer, transaction):
return "\(observer.debugName) updatedTransaction: \(transaction.payment.productIdentifier) " +
[
Expand Down
6 changes: 5 additions & 1 deletion Sources/Purchasing/StoreKit1/StoreKit1Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,12 @@ extension StoreKit1Wrapper: SKPaymentTransactionObserver {
Logger.debug(Strings.purchase.paymentqueue_removed_transaction(self, transaction))
delegate.storeKit1Wrapper(self, removedTransaction: transaction)

if let callbacks = self.finishedTransactionCallbacks.value.removeValue(forKey: transaction) {
if let callbacks = self.finishedTransactionCallbacks.value.removeValue(forKey: transaction),
!callbacks.isEmpty {
callbacks.forEach { $0() }
} else {
Logger.debug(Strings.purchase.paymentqueue_removed_transaction_no_callbacks_found(self,
transaction))
}
}
}
Expand Down

0 comments on commit 4a90351

Please sign in to comment.