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!

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top