Multiple receipt count for restoreCompletedTransaction inapp purchasing

浪子不回头ぞ 提交于 2019-12-11 12:57:35

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/12535420/multiple-receipt-count-for-restorecompletedtransaction-inapp-purchasing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!