okgo
okgo

Reputation: 271

restoreCompletedTransactions broken?

Is restoreCompletedTransactions broken in SDK 4.3 ?

I am trying to restore my auto-renewable subscription. It is not resulting in callback to updatedTransactions. Here is my code.

 {
 ....
 [appDelegate.inapp loadStore];

 [[SKPaymentQueue defaultQueue]  restoreCompletedTransactions];
 ....
 }

Expecting callback to updatedTransactions, but do not receive it.

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
     NSLog(@"IN updatedTransactions,  transaction.transactionState");

    for (SKPaymentTransaction *transaction in transactions)
    {

        switch (transaction.transactionState)
        {
            ...
            ...
            case SKPaymentTransactionStateRestored:
            NSLog(@"IN updatedTransactions,  SKPaymentTransactionStateRestored");
            [self restoreTransaction:transaction];
            break;

        }
    }
}

But I do receive call to this at the end.

-(void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
}

Upvotes: 21

Views: 10772

Answers (7)

Szymon W
Szymon W

Reputation: 578

Two additional points which weren't mentioned here:

  1. If you are using Firebase make sure you add an observer before you initialize Firebase, https://firebase.google.com/docs/analytics/get-started?platform=ios
  2. Make sure that you call finishTransaction method while handling the purchase. You won't be able to restore not completed transactions.

Upvotes: 0

luke1
luke1

Reputation: 1

Make sure your build number in Xcode does not have a space in it. For example "1.0 Beta". With a space updatedTransactions will not be called. Also receipt verification can fail.

Upvotes: 0

Rondinelli Morais
Rondinelli Morais

Reputation: 155

Products Consumable cannot be restored.

Products Non-Consumable can be restored.

Check if your products are type Non-Consumable.

Upvotes: 4

Alaa Eldin
Alaa Eldin

Reputation: 2268

Make sure to add observer before using [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

Your code should be something like:

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

Upvotes: 7

Andreas Ley
Andreas Ley

Reputation: 9335

This can still(1) happen if you're testing in the Sandbox environment and your Test User is broken. Create a new Test User in iTunes Connect, and try again.

It's not entirely clear what makes Test Users go bad; from what I gather, using them once in a non-sandbox environment can do this, but there may be other reasons as well.

(1) Xcode 4.3.1, iOS SDK 5.1

Upvotes: 26

whatchamacallit
whatchamacallit

Reputation: 238

You should not need the updatedTransactions callback if you are getting paymentQueueRestoreCompletedTransactionsFinished. The "queue" has a list of your transactions and you can loop thru those.

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    for (SKPaymentTransaction *transaction in queue.transactions) 
        if ([myItem.productID isEqualToString:transaction.payment.productIdentifier])
            myItem.purchased = YES;
}

Upvotes: 0

Ryan Thomas
Ryan Thomas

Reputation: 61

I was able to get around this but its very odd. On my testing device im getting bugged by iTunes to log in to multiple test user accounts. I usually just hit cancel and test my restore with the account that I want to restore. This time I decided to enter the password for these other annoying login boxes. It worked and next time I relaunched my app and hit restore it did not bug me to log in to the other test accounts, just the one I was testing. I proceeded with the restore and it did restore the items I wanted to see.

Id say were experinecing stupid sandbox issues and also we know apple has changed in app purchasing in general. Keep playing around with it, you'll get it to work out.

Hope this helps you out.

Upvotes: 3

Related Questions