Some tips and fixes for in-app purchases

Some tips and fixes for in-app purchases

Hi there,

while adding in-app-purchases to my app, I encountered several problems. For your convenience, here are the fixes:

I used the moe-samples from here:
(and I simplified them, because I don't need a common android/ios interface)

First I found out that paymentQueueUpdatedTransactions never gets called. It seems that the example code is missing "addTransactionObserver(this)".

So I added this, but then I got a crash instantly.

But thanks to Paul S. ( ) I got that fixed with "ObjCRuntime.associateObjCObject".

After that I got "ios.NSObject cannot be cast to ios.storekit.SKPaymentTransaction".

The example code already had:

static {
  try { Class.forName(SKProduct.class.getName()); }
  catch (ClassNotFoundException e) { }

but the same was needed for SKPaymentTransaction:

static {
  try {
  catch (ClassNotFoundException e) { }

And then I encountered the biggest problem:

Because I initiated an in app purchase, but the purchase never got finished due to the above errors, I then always got "This in app purchase has already been bought. It will be restored for free".

But in this case "paymentQueueUpdatedTransactions" never gets called - so the purchase will never finish!

But thanks to this thread ( ) I found the solution:

Immediately after calling "addTransactionObserver" I called the "paymentQueueUpdatedTransactions"-function manually:


Then, after the apps starts, the purchase finally finished!

Maybe it is a good idea to implement this in every app, because it's always possible that the phone or app crashes just after the purchase. And then you have 2 problems: The in-app-purchase is not activated and if it is a consumable, it couldn't be bought again.

Hope this helps someone...


4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Dear Tobias,

Thank you for the detailed guide!

Best Regards,


Thank you for this information.  I'm going to be trying to integrate In App Purchases also using the MOE example and I'm sure your information will be necessary.

Did you integrate In App Purchases this way from within a LibGdx game?  The reason I ask is because I'm wondering how you did so from the LibGdx side.  (did you just create a new Screen in the game and create a store to show possible purchases?)


@mp: Yes, I'm developing a libGDX app.
I used a normal libGDX screen for the list of products (and not a native iOS UI screen). When the user hits a "buy" button, I call the "purchaseProduct" method. Then iTunes gets into control and my app waits for a response from iTunes.

To find out the prices of the products, I used "requestProductsWithCompletionHandler".


Leave a Comment

Please sign in to add a comment. Not a member? Join today