Dliix
Dliix

Reputation: 716

Swift: Restore In-App purchase, no fail case called

I can buy and restore non-consummable products without any trouble.

But if I try to restore from an account that never bought the product, the method productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) is never called whereas it is called on a successful restore.

Here is my code in the class that conforms to the SKPaymentTransactionObserver protocol:

public func restorePurchases() {
    print("restoring...")
    SKPaymentQueue.default().add(self)
    SKPaymentQueue.default().restoreCompletedTransactions()
}

public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions {

        // finishtTransaction() is called within the sub functions

        switch (transaction.transactionState) {
        case .purchased:
            print("pruchased !")
            complete(transaction: transaction)
            break
        case .failed:
            print("failed !")
            fail(transaction: transaction)
            break
        case .restored:
            print("restored !")
            restore(transaction: transaction)
            break
        case .deferred:
            print("deferred !")
            break
        case .purchasing:
            print("purchasing !")
            break
        default:
            print("default...")
            break
        }
    }
}

Please note that I can buy and restore products, I just never receive an answer when there is nothing to restore.

Upvotes: 2

Views: 629

Answers (1)

Dliix
Dliix

Reputation: 716

In fact, you just need to implement the following method:

public func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
    if (queue.transactions.count == 0)
    {
        print("Nothing to restore...")
    }
}

Upvotes: 6

Related Questions