Clearing SKPAymentsQueue : Forcing Unfinished Transactions To Finish

北城余情 提交于 2020-01-03 05:35:07

问题


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.

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

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

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


回答1:


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


来源:https://stackoverflow.com/questions/36090901/clearing-skpaymentsqueue-forcing-unfinished-transactions-to-finish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!