简体   繁体   English

应用内购买还原

[英]In-App Purchases Restore

I'm trying to do in-app purchases and everything works fine except Restore. 我正在尝试进行应用内购买,除了还原外,一切正常。 Below is the code I have written: 以下是我写的代码:

func paymentQueueRestoreCompletedTransactionsFinished(queue:SKPaymentQueue!)
{
    for transaction:AnyObject in queue.transactions
    {
        let trans : SKPaymentTransaction = transaction as SKPaymentTransaction
        var identifier : NSString = trans.payment.productIdentifier
        println(identifier)
    }
}

The problem that I face here is I'm not getting the purchased identifier here. 我在这里遇到的问题是我没有在这里获得purchased identifier I think I have miswritten the code. 我想我错了代码。

Add below two lines of code on your button click action 在按钮单击操作上添加以下两行代码

SKPaymentQueue.default().restoreCompletedTransactions()
SKPaymentQueue.defaultQueue().addTransactionObserver(self)

Edit - for Swift 3: 编辑 - 适用于Swift 3:

SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()

Riyazul, you need to look at the original transaction when you are restoring purchases. Riyazul,您需要在恢复购买时查看原始交易。

The code you should need is: 您应该需要的代码是:

var identifier : NSString = trans.originalTransaction.payment.productIdentifier

Let me know if it's still not working. 如果它仍然不起作用,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM