我的支付队列中仍有一些恢复事务-因为在测试有缺陷的恢复购买操作时,在事务恢复后,我从未调用过该事务的finishTransaction
。
通过一些在线调查,我意识到我必须手动强制完成付款队列中未完成的交易。
有人在Objective-C中发布了此代码:
// take current payment queue
SKPaymentQueue* currentQueue = [SKPaymentQueue defaultQueue];
// finish ALL transactions in queue
[currentQueue.transactions enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[currentQueue finishTransaction:(SKPaymentTransaction *)obj];
}];
我不知道如何把它转换成Swift 2.0。
有人能帮我吗?谢谢:-)
最佳答案
这里有一个for循环,它将遍历每个挂起的事务并检查状态,并完成失败或成功购买的事务。
let currentQueue : SKPaymentQueue = SKPaymentQueue.default();
for transaction in currentQueue.transactions {
if (transaction.transactionState == SKPaymentTransactionState.failed) {
//possibly handle the error
currentQueue.finishTransaction(transaction);
} else if (transaction.transactionState == SKPaymentTransactionState.purchased) {
//deliver the content to the user
currentQueue.finishTransaction(transaction);
} else {
//handle other transaction states
}
}