I am currently developing and testing my application with a sandbox user. Although the transactions are completed when I try Restore Purchases
, I get as many as 32 old transactions from the queue.
Essentially, I would like to warn both in Your purchase is being restored. Upon completion this dialog will close.
, and dismiss him when he is done.
private func showRestoreInProgressAlert() {
let alert = UIAlertController(title: "Restoring Purchase", message: "Your purchase history is being restored. Upon completion this dialog will close.", preferredStyle: .alert)
present(alert, animated: true, completion: nil)
NotificationCenter.default.addObserver(self, selector: #selector(dismissRestoreInProgressAlert(notification:)), name: SubscriptionService.restoreSuccessfulNotification, object: nil)
}
This method can be recognized below SKPaymentTransactionObserver
. Once the notification .restoreSuccessfulNotification
is sent, the warning will be rejected as expected. But since there are 32 transactions in the queue, a pop-up window appears and disappears 32 times.
func handleRestoredState(for transaction: SKPaymentTransaction, in queue: SKPaymentQueue) {
print("Purchase restored for product id: \(transaction.payment.productIdentifier)")
queue.finishTransaction(transaction)
SubscriptionService.shared.uploadReceipt { (success) in
DispatchQueue.main.async {
NotificationCenter.default.post(name: SubscriptionService.restoreSuccessfulNotification, object: nil)
}
}
}
func paymentQueue(_ queue: SKPaymentQueue,
updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction in transactions {
switch transaction.transactionState {
case .purchasing:
handlePurchasingState(for: transaction, in: queue)
case .purchased:
handlePurchasedState(for: transaction, in: queue)
case .restored:
handleRestoredState(for: transaction, in: queue)
case .failed:
handleFailedState(for: transaction, in: queue)
case .deferred:
handleDeferredState(for: transaction, in: queue)
}
}
}
I am already completing transactions both in handlePurchasedState
and handleRestoredState
as follows:
queue.finishTransaction(transaction)
, , , , " "?
UPDATE
.
, , , .
"hard- reset":
for transaction: AnyObject in SKPaymentQueue.default().transactions {
guard let currentTransaction: SKPaymentTransaction = transaction as? SKPaymentTransaction else {return}
SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
}
, , , Sandbox .
SKPaymentQueue.default().finishTransaction()
, queue.finishTransaction()
? , SKPaymentQueue.default().finishTransaction()
, ? IAP?