Realinstomp
Realinstomp

Reputation: 532

In App Purchase - No purchase to restore

I'm trying to figure out if I get a message back when a user tries to restore an In App Purchase but there was no purchase ever made.

Right now, as soon as a user taps the restoreButton, I disable the restoreButton.

- (IBAction)purchaseRestore:(id)sender {
    NSLog(@"4 IBAction Purchase Restore Method: start");
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
    NSLog(@"4 Purchase Restore: SKPayment Queue two lines... log in user");
    restoreButton.enabled = NO;
    NSLog(@"4 Restore button enabled: No");
}

So if they click the restoreButton, and have nothing to restore then the restoreButton just stays grayed out.

I would like to do something like a UIAlert or change the restoreButton text if that happens to say "You don't have any items to Restore", but I assume I need to get some message back from Apple saying "no items to restore" so I can fire off that code.

Here's my updatedTransactions code if needed:

case SKPaymentTransactionStateRestored:

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"5 Finish Transaction");

                restoreButton.hidden = YES;
                NSLog(@"5 restore button hidden: Yes");

                [self showButtonThree];
                NSLog(@"5 Show Button Three");

                NSLog(@"5 Restored: End");

                break;

Any ideas? Thanks!

Update

Tried this:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
    NSLog(@"Completed Transactions Finished");
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                              @"Restored succesfully" message:nil delegate:
                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];
}

But that was popping up whether there was a transaction to restore or not. I had assumed this would get called if there was no transaction to restore maybe, but makes sense that it wouldn't:

-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
    NSLog(@"Completed Transactions Failed with Error");
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
                              @"Not restored succesfully" message:nil delegate:
                              self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alertView show];
}

Upvotes: 0

Views: 709

Answers (1)

jcaron
jcaron

Reputation: 17710

From the official Apple documentation for restoreCompletedTransactions

After the transactions are delivered, the payment queue calls the observer’s paymentQueueRestoreCompletedTransactionsFinished: method. If an error occurred while restoring transactions, the observer will be notified through its paymentQueue:restoreCompletedTransactionsFailedWithError: method.

Upvotes: 2

Related Questions