IAP_Badger

Hi,

Just started using IAP_Badger - love it, thanks Mongoose Games.

Can anyone tell me the best practice of loading the product catalogue.  Everything works fine in the simulator but I think I am skipping past the getLoadProductsCatalogue step before I’ve got a response.  I cant see an listener for when the getLoadProductsCatalogue call has has a response from Apple/Google and loaded the products.

Thanks

Dean

Hi Dean,

There are two ways of going about this.

The easiest is to call iap.loadProducts as soon as possible after init.init() during your app initialisation (probably during the application.start() event, or in your main.lua file).  Then, later in your app, see what value you get back from iap.getLoadProductsCatalogue().  If you get an empty table (ie. {} rather than nil), you know you are still waiting for your product info.

If you need more than this, you can call iap.loadProducts with a custom listener function.  This will get called every time IAP Badger hears back from the store.   You can use this to interrogate the native Corona event code. or just set a flag to say the catalogue is ready.

Your code would look something like this:

local catalogueReady=nil local function myListener(event)    --Set flag to indicate catalogue ready    catalogueReady=true    --Event contains the native Corona store event if you want to do any further processing end --Initiate product catalogue loading from App Store etc. iap.loadProducts(myListener)

Later in your code, you can just query catalogueReady to check if you have the information back (or not).  Be aware that your listener will receive the standard Corona event data, so product identifiers will be in their raw form - how they are entered in Google Play, the App Store etc., rather than converted back to a standard IAP Badger identifier.

To be fair, most of the time the second method is overkill.  Checking for an empty {} table is enough to see if you’ve heard back from the App Store yet.  Product information usually comes back very quickly, within a few seconds of calling iap.loadProducts(), even over a mobile network.

Thanks that’s brilliant.

I’ve got it working ok by calling it as you suggested at app start up but I think I’ll add the listener just in case.

Thanks again for a great bit of code.

Hi Dean,

There are two ways of going about this.

The easiest is to call iap.loadProducts as soon as possible after init.init() during your app initialisation (probably during the application.start() event, or in your main.lua file).  Then, later in your app, see what value you get back from iap.getLoadProductsCatalogue().  If you get an empty table (ie. {} rather than nil), you know you are still waiting for your product info.

If you need more than this, you can call iap.loadProducts with a custom listener function.  This will get called every time IAP Badger hears back from the store.   You can use this to interrogate the native Corona event code. or just set a flag to say the catalogue is ready.

Your code would look something like this:

local catalogueReady=nil local function myListener(event)    --Set flag to indicate catalogue ready    catalogueReady=true    --Event contains the native Corona store event if you want to do any further processing end --Initiate product catalogue loading from App Store etc. iap.loadProducts(myListener)

Later in your code, you can just query catalogueReady to check if you have the information back (or not).  Be aware that your listener will receive the standard Corona event data, so product identifiers will be in their raw form - how they are entered in Google Play, the App Store etc., rather than converted back to a standard IAP Badger identifier.

To be fair, most of the time the second method is overkill.  Checking for an empty {} table is enough to see if you’ve heard back from the App Store yet.  Product information usually comes back very quickly, within a few seconds of calling iap.loadProducts(), even over a mobile network.

Thanks that’s brilliant.

I’ve got it working ok by calling it as you suggested at app start up but I think I’ll add the listener just in case.

Thanks again for a great bit of code.