@@ -106,7 +106,10 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
106106 private let completeTransactionsController : CompleteTransactionsController
107107 unowned let paymentQueue : PaymentQueue
108108 private var entitlementRevocation : EntitlementRevocation ?
109-
109+ private let restorationDispatchQueue = DispatchQueue (
110+ label: " com.musevisions.SwiftyStoreKit.restorationDispatchQueue " ,
111+ qos: DispatchQoS . background)
112+
110113 deinit {
111114 paymentQueue. remove ( self )
112115 }
@@ -236,19 +239,21 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
236239 * 3. complete transactions (transactionState: .purchased, .failed, .restored, .deferred)
237240 * Any transactions where state == .purchasing are ignored.
238241 */
239- var unhandledTransactions = transactions. filter { $0. transactionState != . purchasing }
240-
241- if unhandledTransactions. count > 0 {
242-
243- unhandledTransactions = paymentsController. processTransactions ( transactions, on: paymentQueue)
244-
245- unhandledTransactions = restorePurchasesController. processTransactions ( unhandledTransactions, on: paymentQueue)
246-
247- unhandledTransactions = completeTransactionsController. processTransactions ( unhandledTransactions, on: paymentQueue)
242+ restorationDispatchQueue. sync {
243+ var unhandledTransactions = transactions. filter { $0. transactionState != . purchasing }
248244
249245 if unhandledTransactions. count > 0 {
250- let strings = unhandledTransactions. map { $0. debugDescription } . joined ( separator: " \n " )
251- print ( " unhandledTransactions: \n \( strings) " )
246+
247+ unhandledTransactions = paymentsController. processTransactions ( transactions, on: paymentQueue)
248+
249+ unhandledTransactions = restorePurchasesController. processTransactions ( unhandledTransactions, on: paymentQueue)
250+
251+ unhandledTransactions = completeTransactionsController. processTransactions ( unhandledTransactions, on: paymentQueue)
252+
253+ if unhandledTransactions. count > 0 {
254+ let strings = unhandledTransactions. map { $0. debugDescription } . joined ( separator: " \n " )
255+ print ( " unhandledTransactions: \n \( strings) " )
256+ }
252257 }
253258 }
254259 }
@@ -262,11 +267,15 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
262267 }
263268
264269 func paymentQueue( _ queue: SKPaymentQueue , restoreCompletedTransactionsFailedWithError error: Error ) {
265- restorePurchasesController. restoreCompletedTransactionsFailed ( withError: error)
270+ restorationDispatchQueue. async { [ weak self] in
271+ self ? . restorePurchasesController. restoreCompletedTransactionsFailed ( withError: error)
272+ }
266273 }
267274
268275 func paymentQueueRestoreCompletedTransactionsFinished( _ queue: SKPaymentQueue ) {
269- restorePurchasesController. restoreCompletedTransactionsFinished ( )
276+ restorationDispatchQueue. async { [ weak self] in
277+ self ? . restorePurchasesController. restoreCompletedTransactionsFinished ( )
278+ }
270279 }
271280
272281 func paymentQueue( _ queue: SKPaymentQueue , updatedDownloads downloads: [ SKDownload ] ) {
0 commit comments