InApp Purchases - paymentQueue: updatedTransactions not called from a specific location

I have two places when I launch the same UIView with the option to purchase the purchased InApp product. 1. User shutdown 2. Standard menu location

From the 1st day payment begins. I get updated transactions with SKPaymentTransactionStatePurchasing:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { DLog(@"updatedTransactions"); for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStatePurchased: // I get here when the controller is initiated from menu, not from my user onboarding break; case SKPaymentTransactionStateFailed: [self failedTransaction:transaction]; break; case SKPaymentTransactionStateRestored: [self restoreTransaction:transaction]; break; case SKPaymentTransactionStatePurchasing: // I get here break; default: break; } } } 

But then this method is never called when the user completes the transaction.

When I start the same controller from the menu, everything works fine.

Any ideas?

thanks

+5
source share
1 answer

Perhaps you are installing the wrong transaction observer (or not installing it) in one of the two controllers mentioned.

To receive notifications when a transaction is updated, you must add an observer as follows:

 [[SKPaymentQueue defaultQueue] addTransactionObserver:something]; 

where something can be self (if your paymentQueue:updatedTransactions: method is on self ) or another object.

If you put the appropriate code for the two controllers (controller names and calls to the addTransactionObserver: method mentioned above, plus a little context), I can give you more information, but before that I can make some assumptions.

Suppose you have two controllers:

UserOnboardingController
UpgradeController

You say that it works correctly in the UpgradeController , this is probably due to the fact that when loading the controller (for example, in viewDidLoad: there is a call

 [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; 

and paymentQueue:updatedTransactions: is one of the UpgradeController methods.

However, when you are on the UserOnboardingController , you are not calling or passing the wrong observer to the addTransactionObserver: method.

If so, you should:

  • get the correct observer from the ViewController hierarchy and pass it as an observer
  • move transaction observer code to a common class (for example, in AppDelegate or another specific singleton class)
+2
source

Source: https://habr.com/ru/post/1266679/


All Articles