Restoring an in app purchase with a user who never

2019-03-28 18:35发布

问题:

I'm trying to test the in app purchase in my app.

When i restore the in app purchase with a test user who bought the in app purchase it all works fine.

But when i try to restore an in app purchase with a user who didn't make the in app purchase before i expected the framework to call the following method:

-paymentQueue:restoreCompletedTransactionsFailedWithError:

but instead the framework calls:

-paymentQueueRestoreCompletedTransactionsFinished:

like my test user already bought the in app purchase....

Is this the normal behavior? And if so, how do i test a user trying to restore without ever purchasing the in app purchase?

回答1:

See the answer here: iOS in-app-purchase restore returns many transactions

You'll have to handle it in transaction observer.

In short, you start restore process with:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

Then following transaction observer is called:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    int thisIsTheTotalNumberOfPurchaseToBeRestored = queue.transactions.count;

    for (SKPaymentTransaction *transaction in queue.transactions)
    {
        NSString *thisIsProductIDThatHasAlreadyBeenPurchased = transaction.payment.productIdentifier;

        if([thisIsProductIDThatHasAlreadyBeenPurchased isEqualToString:product1ID])
        {
            //Enable product1 here
        }
    }
}


回答2:

Try MKStoreKit framework https://github.com/MugunthKumar/MKStoreKit It is pretty good, well maintained framework. I have a few apps with in-app purchases. Never had any issues like that.



回答3:

@Tibidabo I wouldn't recommend MKStoreKit because it has a big hole in restore purchased items functionality.