1

I have the app on the AppStore where restore purchases work fine (the build is done with Swift 2.2). However, I just switched to Swift 3 and xCode 8 and restoreCompletedTransactions stopped working. The paymentQueue is not called and paymentQueueRestoreCompletedTransactionsFinished returns 0 transactions in the queue for the real appleId user on the iTuneStore. However, when I switched to the sandbox test account it worked (even in Swift 3). Here is the code... Does anyone know if there are some changes regarding this in xCode 8?

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

        switch transaction.transactionState {
        case SKPaymentTransactionState.purchased:
            NSLog("Transaction completed successfully.")
            SKPaymentQueue.default().finishTransaction(transaction)
            transactionInProgress = false
            if (self.selectedProductIndex != -1)
            {
                delegate.didBuyTraining()
            }
            break


        case SKPaymentTransactionState.failed:
            NSLog("Transaction Failed");
            SKPaymentQueue.default().finishTransaction(transaction)
            transactionInProgress = false
            break

        case SKPaymentTransactionState.restored:
            NSLog("Transaction completed successfully.")
            SKPaymentQueue.default().finishTransaction(transaction)
            transactionInProgress = false
            break

        default:
            NSLog(String(transaction.transactionState.rawValue))
            break
        }
    }
}

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue!) {
    var productIds = [String]()
    let count = queue.transactions.count
        for var transaction in queue.transactions{
        let prodID = transaction.payment.productIdentifier 
        productIds.append(prodID)
    }
    for var prodID in productIds {
        for var prod in productsArray {
            if prod?.productIdentifier == prodID{
                set_defaults((prod?.localizedTitle)!)
            }
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jela
  • 51
  • 5
  • "However, when I switched to the sandbox test account it worked" But that is the only way you _can_ test it. So it works. What is the sense in which it _doesn't_ work? – matt Sep 23 '16 at 03:08
  • It doesn't work when I use an actual appIeD and connect to the iTunesStore. I'm trying it from xCode, as I still didn't update the the app on the appstore. Or maybe in development environment that is how it's supposed to work? Just with the sandbox account and you can't use an actual user appleID that you previously purchased with? – Jela Sep 23 '16 at 12:48
  • 1
    Just found an answer to my question here http://stackoverflow.com/questions/13498005/ios-in-app-purchase-test-a-real-purchase-without-submitting-to-apple "...Short answer: you can't test a real purchase (aka, spend real money) Slightly longer answer: You'll automatically hit the sandbox environment unless it's a apple-signed release build. Even ad-hoc signed builds hit the sandbox..." – Jela Sep 23 '16 at 13:04
  • That is what I said. The sandbox is the only way you can test. – matt Sep 23 '16 at 13:18

0 Answers0