使用 restoreCompletedTransactions() 时没有得到任何响应

Not getting any response when using restoreCompletedTransactions()

我已经在我的应用中实现了应用内购买。购买工作正常,但我无法恢复购买。

按下 restorepurchasenow 时没有任何反应,尽管我已经在支付队列中实施了 SKPaymentTransactionState.Restored 案例。我正在使用沙盒用户来测试这个,会不会是问题?

这是我的代码:

@IBAction func restorepurchasesnow(sender: AnyObject) {


if transactionInProgress {
    return
}

    SKPaymentQueue.defaultQueue().addTransactionObserver(self)
    SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
    restorepurchase.setTitle(NSLocalizedString("settings.inprogress", comment: "Transaction in progress"), forState: UIControlState.Normal)
    self.transactionInProgress = true
    println("Trying to restore purchases") // I get this message


}

func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {

    println("did receive answer from server") // this never gets fired


    for transaction in transactions as! [SKPaymentTransaction] {

        switch transaction.transactionState {

        case SKPaymentTransactionState.Purchased:
            println("Transaction completed successfully.")
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false
            removeads.setTitle(NSLocalizedString("settings.proenabled", comment: "Pro version purchased"), forState: UIControlState.Normal)
            didpurchaseremoveads()


        case SKPaymentTransactionState.Failed:
            println("Transaction Failed");
            SKPaymentQueue.defaultQueue().finishTransaction(transaction)
            transactionInProgress = false


        case SKPaymentTransactionState.Restored:
            let prodID = transaction.payment.productIdentifier as String
            println(prodID)
                if prodID == "removeads" {

                    println("Purchase restored")
                    SKPaymentQueue.defaultQueue().finishTransaction(transaction)
                    removeads.setTitle(NSLocalizedString("settings.proenabled", comment: "Pro version purchased"), forState: UIControlState.Normal)
                    restorepurchase.setTitle(NSLocalizedString("settings.restore", comment: "Restore purchases"), forState: UIControlState.Normal)
                    transactionInProgress = false
                    didpurchaseremoveads()

                } else {

                    transactionInProgress = false
                    println("Puchase restaured but no compatible products were found")
                    restorepurchase.setTitle(NSLocalizedString("settings.restore", comment: "Restore purchases"), forState: UIControlState.Normal)
                }

        default:
            println(transaction.transactionState.rawValue)
        }
    }
}

编辑:

我已经实现了:

   func paymentQueue(queue: SKPaymentQueue!,
        restoreCompletedTransactionsFailedWithError error: NSError!){

            println(error)
    }

我收到以下错误:Domain=SKErrorDomain Code=0 "Cannot connect to iTunes Store" UserInfo=0x17427c840 {NSLocalizedDescription=Cannot connect to iTunes Store} 什么原因?

您运行在模拟器中进行此操作吗?如果是这样,我相信您无法通过这种方式完全完成恢复购买。我认为它必须是 运行 在设备上。基本上模拟器不支持StoreKit.