事务在finishTransaction之后返回:已经调用它 [英] Transaction comes back after finishTransaction: has been called on it

查看:1417
本文介绍了事务在finishTransaction之后返回:已经调用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用应用内购买iPhone应用。我有一个类充当 SKProductsRequestDelegate SKPaymentTransactionObserver ,它在iTunes上当前发布的版本中运行良好。

I am using in-app purchase for an iPhone app. I have a class that acts as SKProductsRequestDelegate and SKPaymentTransactionObserver, and it's all working fine in the currently released version available on iTunes.

然而,在最近添加一个新的非消费品并在Sandbox环境中测试之后,我现在遇到了一个奇怪的问题。每次我启动应用程序时,我昨天所做的购买重新出现在 paymentQueue:updatedTransactions:传递给我的交易列表中,尽管我已经调用了 [[SKPaymentQueue defaultQueue] finishTransaction:transaction] 已经(好几次)。这是不死生物!

However, after recently adding a new non-consumable product and testing it within the Sandbox environment, I'm now encountering a strange problem. Every time I launch the app, the purchase I made yesterday reappears in the transactions list passed to me by paymentQueue:updatedTransactions:, despite the fact that I had called [[SKPaymentQueue defaultQueue] finishTransaction:transaction] already (several times). It's undead!

在我的 paymentQueue:updatedTransactions:实施中,我有:

for (SKPaymentTransaction* transaction in transactions) 
    switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchased:
        case SKPaymentTransactionStateRestored:
        {
            ....
                DDLog(@"Transaction for %@ occurred originally on %@.", transaction.payment.productIdentifier, transaction.originalTransaction.transactionDate);
                ....

然后我处理购买,下载用户内容,最后,在另一种方法中,执行以下操作:

I then process the purchase, download the user content and finally, in another method, do this:

for (SKPaymentTransaction* transaction in [[SKPaymentQueue defaultQueue] transactions])         
            if (([transaction.payment.productIdentifier isEqualToString:theParser.currentProductID]) &&
                 ((transaction.transactionState==SKPaymentTransactionStatePurchased) || (transaction.transactionState==SKPaymentTransactionStateRestored))
               )
            {
                DDLog(@"[[ Transaction will finish: product ID = %@; date = %@ ]]", transaction.payment.productIdentifier, transaction.transactionDate);
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            }

您可能已经注意到,我没有坚持原始交易对象是为了简单起见,以后从调用 [[SKPaymentQueue defaultQueue] transactions] 中查找它相对容易。无论如何,我确实看到了预期的输出;交易完成,并且它与产品ID和原始交易的日期精确匹配。但是,下次我运行应用程序时,整个事情重新开始!这就像iTunes商店从未通知交易已完成或拒绝承认。

As you may have noticed, I'm not holding on to the original transaction object for the sake of simplicity, and it's relatively easy to find it later from the call to [[SKPaymentQueue defaultQueue] transactions]. Regardless, I do indeed see the expected output; that the transaction is completed and that it precisely matches the product ID and date of the original transaction. However, next time I run the app the whole things starts over! It's like the iTunes Store was never notified that the transaction completed, or refuses to acknowledge it.

推荐答案

此问题也在开发者论坛,一般的结论是它在iPhone OS 4.0中处理事务的差异。只有在收到已完成交易的通知与在支付队列上调用 finishTransaction 之间存在显着延迟时,才会出现此问题。最后我们找不到理想的解决方案,但我们做的是:

This issue was also raised in the developer forums, and the general conclusion was that it was down to a difference in the handling of transactions in iPhone OS 4.0. The problem only seems to occur when there is a significant delay between receiving a notification of the finished transaction and calling finishTransaction on the payment queue. In the end we didn't find an ideal solution, but what we did was this:


  1. 交易一到达,如果处理成功,则处理它并在用户首选项中记录一个值。

  1. As soon as the transaction arrives, process it and record a value in the user preferences if processing was successful.

下次该事务出现在队列中时,可能直到下次启动应用程序,立即在其上调用 finishTransaction

The next time that transaction appears in the queue, which may not be until the next launch of the app, immediately call finishTransaction on it.

我们的产品是非消耗品,因此足以检查所支付的产品是否有效且无错误,以安全地忽略来自iTunes的任何不死重复交易。对于消费品,需要保存有关购买的更多信息,例如原始付款日期,以确保未来的交易通知可以与已经处理的购买相匹配。

Our products are "non-consumable" so it's enough to check that the product paid for is valid and error-free to safely ignore any 'undead' repeated transactions from iTunes. For consumable products one would need to save more information about the purchase, such as the original payment date, to make sure that future transaction notifications can be matched to purchases that were already processed.

这篇关于事务在finishTransaction之后返回:已经调用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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