如何从用户的iOS设备上的已完成购买中获取应用内购买收据?购买后,我们需要在购买后立即验证收据(最好在SKPaymentTransactionObserver
)。否则,当我们尝试单独验证本地收据时......它已经过时了!
以下是我的交易观察员:
extension StoreManager: SKPaymentTransactionObserver {
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
print("Received Payment Transaction Response from Apple");
for transaction:AnyObject in transactions {
// check object is a transaction first
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
print("Product Purchased");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
// invoke any callback waiting to be called
purchaseCallbackHolder?([trans.pseudoReceipt]) // here is where I'd like to extract the receipt associated with the transaction
purchaseCallbackHolder = nil
break;
case .Failed:
print("Purchased Failed");
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break;
}
}
}
}
}
请注意,上面我写了代码trans.pseudoReceipt
。这里的问题是我无法从交易中提取任何收据。但是,当我检查本地收据时...它没有更新!谢谢你的帮助。