I have an auto-renewal subscription. When the application is installed on a new device, Apple returns ALL previous purchase receipts, in this case, since it is a sandbox, I get 6 receipts every time I install. Then, the observer sends a queue for restored completed transactions. I have a way to send a transaction to my server for Apple verification, but it works 6 times due to 6 receipts. I really want to deal with the sent LAST dispatch.
So, I am trying to count the transactions in the queue and ONLY check the receipt when the counter reaches 1.
Here is what I still have:
- (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; }
Recovery continues cyclically, but the counter does not decrease. This is probably something simple and dumb. Can someone show me how to reduce this score?
Thanks!
source share