EDIT:
I originally posted a very long unnecessary method to get what I needed, but as you will see below, Matt helped me figure out the variable I was looking for.
As an example, suppose a user who previously purchased my application bought all inaccessible IAPs and then uninstalled the application. When a user reinstalls the application, I want to be able to determine when they will start “buying” products again, will it be the original (first) purchase or purchase of restoration?
I implemented the “Restore all purchases” button, but let the user ignore / not see it and try to select the product they bought before.
As with a regular purchase, I do the following:
if ([SKPaymentQueue canMakePayments]) { self.productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:productID]]; self.productRequest.delegate = self; [self.productRequest start]; } else {
After the user has registered in their iTunes account, the application will inform them that they have already purchased this, and now it will be restored. The following delegate method will be called:
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchased: { [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; if(transaction.originalTransaction) { NSLog(@"Just restoring the transaction"); } else { NSLog(@"First time transaction"); } break; } default: break; } } }
Regardless of whether the transaction was a reinstatement or purchase for the first time, transaction.transactionState will equal SKPaymentTransactionStatePurchased .
Now from now on we can determine whether this purchase is an original or replacement purchase?
Just. As seen above, just check if transaction.originalTransaction initialized. Apple Note: // Valid only if the status is SKPaymentTransactionStateRestored.
If SKPaymentTransaction originalTransaction initialized, it means that there was a previous transaction. Otherwise, this transaction is original!
Thanks again to Matt for pointing me in the right direction and making the logic a lot cleaner!