Home:ALL Converter>Multiple receipt count for restoreCompletedTransaction inapp purchasing

Multiple receipt count for restoreCompletedTransaction inapp purchasing

Ask Time:2012-09-22T01:35:59         Author:PrivusGuru

Json Formatter

I have an autorenewable subscription. When the app is installed on a new device, Apple returns ALL previous purchase receipts, in this case since it is sandbox I get 6 receipts every time I install. The observer then sends the queue for restoredCompleted transactions. I have a method to send the transaction to my server for Apple verification, but it runs 6 times because of the 6 receipts. I really only want to deal with the LAST receipt sent.

So I am trying to count the transactions in the queue and ONLY verify the receipt when the count reaches 1.

Here is what I have so far:

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

The restore cycles through, but the count does not decrement. This is probably something simple and dumb. Can someone show me how to decrement this count?

Thanks!

Author:PrivusGuru,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12535420/multiple-receipt-count-for-restorecompletedtransaction-inapp-purchasing
yy