1

I have implemented additional receipt verification for in-app purchases in my application (inspired by https://developer.apple.com/library/ios/#releasenotes/StoreKit/IAP_ReceiptValidation/_index.html). So, after I get SKPaymentTransactionStatePurchased, I perform this validation, and on success, I unlock the game's new content and, finally, I finish the transaction by

[[SKPaymentQueue defaultQueue] finishTransaction:myTransaction];

What happens if verification process cannot be finished say due to internet connection failure or if the user terminates the application during verification process? In this case I do not unlock content and do not finish the transaction. And I think it's rather logical.

However, when I restarted the application (that had been terminated in "unfinished transaction" state) and tried to purchase the in-app, I fell into SKPaymentTransactionStateFailed state with transaction.error.code == SKErrorPaymentCancelled. Also a message box appeared that said:

"You have already purchased this item, but it is not yet loaded. Tap "OK" to load it now."

After pressing "OK", I do not get any callback called - and hence I did not unlock the content.

So my questions are: 1) Is it OK to left transaction in unfinished state (if it cannot be verified)? 2) And how do I restore it? Maybe I'm missing some callback that accompanies "You have already purchased..." messagebox?

P.S. My in-app purchase is "consumable". So I cannot use

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
Nick
  • 3,205
  • 9
  • 57
  • 108

1 Answers1

2

Okay, I resolved it. The essential thing is to listen to payment queue from App Delegate, not from "purchasing UI screen". In other words,

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

must be in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

not in my custom purchasing screen's viewDidLoad.

Great explanation can be found here: When should i validate in-app purchase transaction receipt?

Community
  • 1
  • 1
Nick
  • 3,205
  • 9
  • 57
  • 108