如何判断购买了哪个IAP?

How to determine which IAP was purchased?

我正在 swift 中编写一些代码来处理 IAP。您如何确定在 paymentQueue 函数中购买了哪个 IAP?

这是我目前的代码:

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

    println("Received Payment Transaction Response from Apple")

    for transaction:AnyObject in transactions {
        if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
            switch trans.transactionState {
            case .Purchased:
                println("Product Purchased");
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as SKPaymentTransaction)
                break;
            case .Failed:
                println("Purchased Failed");
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as SKPaymentTransaction)
                break;
            case .Restored:
                println("Product Restored");
                SKPaymentQueue.defaultQueue().finishTransaction(transaction as SKPaymentTransaction)
                // case .Restored:
                //[self restoreTransaction:transaction];
            default:

                break;
            }
        }
    }
}

从交易中,您可以获得付款,其中包含产品标识符。

https://developer.apple.com/library/prerelease/ios/documentation/StoreKit/Reference/SKPaymentRequest_Class/index.html#//apple_ref/doc/c_ref/SKPayment

SKPaymentTransaction实例的payment属性的productIdentifier值给你相关的产品。


您可以在 its Class Reference 中阅读有关 SKPaymentTransaction 的更多信息。