清除SKPAymentsQueue:强制完成未完成的事务 [英] Clearing SKPAymentsQueue : Forcing Unfinished Transactions To Finish

查看:197
本文介绍了清除SKPAymentsQueue:强制完成未完成的事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些恢复交易仍然停留在我的支付队列中 - 因为我在测试有缺陷的恢复购买操作时,一旦恢复了该事务,我从未调用 finishTransaction

I have some restore transactions still stuck in my payments queue - because I never called finishTransaction with the transaction once it was restored when I was testing a flawed restore purchases action.

从一些在线调查中,我发现我必须手动强制完成我的付款队列中未完成的交易。

From some online research, I realise I have to manually force unfinished transactions in my payments queue to finish.

有人在Objective-C中发布了此代码:

Someone posted this code in 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。

I have no idea how to convert it to Swift 2.0.

任何人都可以帮助我这样做吗?谢谢: - )

Can anyone pls help me do this? Thanks :-)

推荐答案

这是一个for循环,它将遍历每个待处理的事务并检查状态,并完成已失败或成功购买。

Here is a for loop that will iterate through each pending transaction and check the state, and complete transactions that have either failed or successfully purchased.

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
            }
        }

这篇关于清除SKPAymentsQueue:强制完成未完成的事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆