Multiple receipt count for restoreCompletedTransaction inapp purchasing
Asked Answered
C

1

1

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!

Crenulate answered 21/9, 2012 at 17:35 Comment(1)
Shouldn't you place an int before tCount =myQueue.transactions.count; to declare tCount as an integer?Appraisal
C
2

I wait until restoreCompletedTransactionsFinished before sending a receipt to my server to verify with Apple. This eliminates sending every receipt, which after a few months could get onerous. So, no need to decrement to transaction cout.

Crenulate answered 9/10, 2012 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.