Questions about Defold IAP difference between Android and iOS (SOLVED)

Just wanted to share some IAP confusion I’m seeing on Android; when I use iap.buy() on Android and cancel it, a previous non-consumable purchase is returned. Is this expected behaviour?

I went to the docs to get clarity, and then I noticed that iap.buy() “Sets the listener function for In-app purchase events.” rather than “requests a purchase” or something along those lines.

But there is also iap.set_listener():

https://defold.com/extension-iap/#buy

All a bit strange. It’s been a long day.

Until you call iap.finish() on a transaction it will keep being returned to you when you set the listener (and maybe also after each call to iap.buy()).

On Android it is returned, but not on iOS. These are the differences in behaviour that I’ve spotted so far:

  • Android returns TRANS_STATE_PURCHASED automatically after init for purchases that have not been consumed. iOS doesn’t.
  • iap.buy() also returns TRANS_STATE_PURCHASED for items that have previously been purchased, on top of the item requested. iOS returns only the requested item.
  • iOS returns TRANS_STATE_RESTORED after calling iap.restore(). Android returns TRANS_STATE_PURCHASED.

There is bound to be differences. In-app purchases actually do not work exactly the same on Android and iOS.

  • On iOS there is a concept of restoring purchases: iap.restore(). This doesn’t really exist on Android.
  • On Android there are two types of products: subscriptions and consumables. You can simulate non-consumable products by not calling iap.finish().
  • On iOS there are three types of products: subscriptions, consumables and non-consumables.

Is any of this causing you actual problems or is it merely a note that things behave differently?

1 Like

The consumable difference is fine and can be taken care of easily enough. The things that are confusing to me, and probably anyone who’s working with IAPs on Defold, are the undocumented (as far as I know) differences in behaviour I mentioned above.

I’ve documented this here: https://github.com/defold/extension-iap/blob/master/docs/index.md#differences-between-supported-platforms

2 Likes

Brilliant, thanks! The world is a better place.

2 Likes