应用购买中restoreCompletedTransactions的多次收据计数

时间:2012-09-21 17:35:59

标签: ios in-app-purchase auto-renewing

我有一个可自动更新的订阅。当应用程序安装在新设备上时,Apple会返回所有以前的购买收据,在这种情况下,因为它是沙盒,所以每次安装时都会收到6个收据。然后,观察者将队列发送到restoredCompleted事务。我有一种方法将交易发送到我的服务器进行Apple验证,但由于6个收据,它运行了6次。我真的只想处理最后发送的收据。

所以我正在尝试计算队列中的交易,并且只在计数达到1时验证收据。

这是我到目前为止所做的:

    - (void)paymentQueue: (SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
if (myQueue == nil) {
    myQueue = [SKPaymentQueue defaultQueue];
}

NSLog(@"Transactions in Array  in My Store %@", [queue transactions]); 
tCount =myQueue.transactions.count;
NSString *transCount =  [NSString stringWithFormat:@"%d",tCount];

for (SKPaymentTransaction *transaction in transactions)       

{ switch (transaction.transactionState)     

    { case SKPaymentTransactionStatePurchased:
            [self completeTransaction: transaction];
            break;

        case SKPaymentTransactionStateFailed:
            [self failedTransaction: transaction];
            break;

        case SKPaymentTransactionStateRestored:                

            if  ([transCount isEqualToString:@"1"]) {
                [self restoreTransaction: transaction];
            }

            else {
               tCount--;

                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                });
            }


        default:
            break;

          }
      }
    return;        
   }

恢复循环,但计数不会减少。这可能是简单而愚蠢的事情。有人能告诉我如何减少这个数量吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

我等到restoreCompletedTransactionsFinished,然后将收据发送到我的服务器以验证Apple。这样就无法发送每张收据,这些收据在几个月后就会变得繁重。所以,不需要减少交易cout。