Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InApp Purchases - paymentQueue: updatedTransactions is not called from specific place

I have two places when I initiate the same UIView with possibility to buy an InApp purchasable product. 1. End of user onboarding 2. Standard place in menu

From the 1st one the payment is initiated I get to the updatedTransactions 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 user finish the transaction.

When I initiate the same controller from the menu everything works fine.

Any ideas?

Thank you

like image 352
David Avatar asked Apr 13 '17 08:04

David


1 Answers

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

In order to receive notifications when a transaction is updated, you have to add the observer this way:

[[SKPaymentQueue defaultQueue] addTransactionObserver:something];

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

If you post the relevant code of the two controllers (controller names and calls to the addTransactionObserver: method mentioned above plus a bit of context) I can give you more informations, but until then I can make some assumption.

Let's assume that you have two controllers:

UserOnboardingController
UpgradeController

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

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

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

However, when you are on UserOnboardingController, you don't call or pass the wrong observer to addTransactionObserver: method.

If this is the situation, you should:

  • retrieve the correct observer from your ViewController hierarchy and pass in as observer
  • move the code of the transaction observer on a shared class (for example on the AppDelegate or another specific singleton class)
like image 84
LombaX Avatar answered Oct 22 '22 20:10

LombaX