使用swift,iOS恢复InApp购买 [英] Restore InApp purchase using swift, iOS
本文介绍了使用swift,iOS恢复InApp购买的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在应用购买中实施恢复。我有一个按钮,其动作是
I am implementing restore in app purchase. I have a button whose action is
@IBAction func restorePurchases(send : AnyObject){
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
// if (success) {
// I want to do something here
// }
}
我的问题是。
- 这是正确的恢复方式?
- 我们如何验证恢复购买的成功行动?
推荐答案
不要忘记检查您是否可以付款:
don't forget to check if you can make a payment:
if (SKPaymentQueue.canMakePayments()) {
SKPaymentQueue.default().restoreCompletedTransactions()
}
要检查恢复是否良好,你必须遵循协议:
SKPaymentTransactionObserver
然后实现方法:
for check if the restore was good you have to follow the protocol:
SKPaymentTransactionObserver
and then implement the method:
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!)
并通过以下方式订阅活动:
and subscribe to the event by doing:
SKPaymentQueue.default().add(self)
最后这里是我检查结果的例子:
Finally here is an exemple of how I check the result:
func paymentQueue(_ queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!) {
print("Received Payment Transaction Response from Apple");
for transaction in transactions {
switch transaction.transactionState {
case .purchased, .restored:
print("Purchased purchase/restored")
SKPaymentQueue.default().finishTransaction(transaction as SKPaymentTransaction)
break
case .failed:
print("Purchased Failed")
SKPaymentQueue.default().finishTransaction(transaction as SKPaymentTransaction)
break
default:
print("default")
break
}
}
}
这篇关于使用swift,iOS恢复InApp购买的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文