Transaction comes back after finishTransaction: has been called on it

后端 未结 10 1151
一个人的身影
一个人的身影 2020-12-08 15:06

I am using in-app purchase for an iPhone app. I have a class that acts as SKProductsRequestDelegate and SKPaymentTransactionObserver, and it\'s all

10条回答
  •  佛祖请我去吃肉
    2020-12-08 15:30

    I had the same issue but I solved it.

    Here's my code:

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
    {
        for (SKPaymentTransaction * transaction in transactions)
        {
            switch (transaction.transactionState)
            {
                case SKPaymentTransactionStatePurchased:
                    [self completeTransaction:transaction];
                    break;
                case SKPaymentTransactionStateFailed:
                    [self failedTransaction:transaction];
                    break;
                case SKPaymentTransactionStateRestored:
                    [self restoreTransaction:transaction];
                    break;
                default:
                    break;
            }
        }
    }
    
    - (void)completeTransaction:(SKPaymentTransaction *)transaction
    {
        NSLog(@"completeTransaction... %@", [[transaction class] description]);
    
        [self provideContentForProductIdentifier:transaction];
    }
    
    - (void)restoreTransaction:(SKPaymentTransaction *)transaction
    {
        NSLog(@"restoreTransaction...");
    
        [self provideContentForProductIdentifier:transaction.originalTransaction];
    }
    

    I was then calling finishTransaction: method inside provideContentForProductIdentifier: method. And in case of restore transaction I was calling finishTransaction: to the originalTransaction object not the transaction itself.

    I solved my issue by this code (method restoreTransaction:)

    - (void)restoreTransaction:(SKPaymentTransaction *)transaction
        {
            NSLog(@"restoreTransaction...");
    
            //Pass the main transaction object.
            [self provideContentForProductIdentifier:transaction];
        }
    

提交回复
热议问题