Unable to finish unfinished transactions in payment queue

核能气质少年 提交于 2019-12-03 02:25:49

I'm putting this here because there are a lot of really bad, bad answers out there that provide WRONG information on how to resolve this problem. It is not that rare, or mysterious or an Apple bug, it's part of the App store design and there to help you get your IAP built right.

DO NOT:

  • Ever, ever, ever delete the sandbox test user. This makes it impossible to resolve the problem and you will be in endless loop hell until the transaction eventually goes away.... it does go away but it takes a long time, like days or weeks.
  • If you delete the sandbox test user, when you are subsequently repeatedly prompted (like EVERY TIME your App sets up IAP) to log into the test user store account to finish the transaction, you can't because the user has been deleted. Nor will you be able to add the test user back because the developer portal will say that user id has already been used.
  • Do not: delete the App or re-install iOS or any other such BS. It has no effect, doesn't solve the problem and wastes a lot of time.

DO:

  • Call FINISH on ALL transactions. If one is interrupted for some reason, simply complete on a subsequent run of the App. The app will be repeatedly sent the payment queue notice until you call finish on it, giving you the opportunity to call [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; This is intentional and a pre-caution against interrupted transactions.

That's it! Finish all transactions, else you will be sent to the Endless Loop hell of repeated requests to sign into a non-existent test user App Store account every single time your App launches on that device :(

You might need to repeat these steps a few times to it to work. Finish the transaction as soon as your transaction observer delegate method is called.

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{    
    for (SKPaymentTransaction *transaction in transactions) {

        // Temporary code to solve the loop issue
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

        /*
        switch (transaction.transactionState) {
        // Call the appropriate custom method.
        case SKPaymentTransactionStatePurchased:
            [self completeTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
            [self failedTransaction:transaction];
            break;
        case SKPaymentTransactionStateRestored:
        default:
            break;
        }
        */
    }
}

Now you run the app and login with the deleted sandbox account. The method above should fire and finish the transaction right away. If the transactions array is nil, try calling the finish code before the FOR loop.

I got this to work again by calling the following code to be executed once. You may be asked a last time for the password to be entered, but after the code has been executed, the "exorcism" is done and you're free to remove the code again.

#ifdef DEBUG
    for (SKPaymentTransaction *transaction in [[SKPaymentQueue defaultQueue] transactions]) {
        NSLog(@"finish transactions pending sind last load...");
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    }
#endif
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!