IAP: get Product Information just before the purchase or once at app launch?

Hi,

as you need to get product information before you can initiate a purchase, I wonder if its ok doing it once when the app launches, or do I have to do it just before the purchase - like it will get invalid after a while...

Replies

Hi @Niano,

I would recommend getting the product information (via SKProductsRequest) whenever you display your in-app purchases to the user in your UI.

The call to SKProductsRequest, and the subsequent SKProductsResponse received via SKProductsRequestDelegate's didReceive method is lightning fast, so you don't have to worry about lag times.

This also means you can be sure that your products, prices, etc. are always bang up to date whenever the user needs/asks to see them.

Finally, if there is no network connection when the SKProductsRequest happens - and you therefore can't get the product information you need for the purchase - you can then add logic that states this to the user via an alert and then escapes the view controller, allowing the user another opportunity to try again once there is network connection and thus ensuring you always have that product information before going through with the purchase. You'll know there has been an error getting it if SKProductsRequestDelegate's didFailWithError method gets called and requestDidFinish doesn't.

Does this strategy make sense?

Cheers, Ben

Hi Ben,

thank you for your detailled answer!

My UI is made in a way that there is a specific screen to buy in-app-producs, and I wanted to not only query the information when the user opens it, because I fear that if their connection is very slow, or Apples servers, or something like that, there will be a delay before the prices on the buy buttons are shown, which I think would look terrible.

So I query the prices when the app launches and store them, so I can show them to the user instantly. Now I don't worry about the data beeing old when the user sees it (I don't plan to make changes to them ever), but just wonder if a problem could arise when they were queried lets say a few hours ago. I also find this relatively hard to test as it seems the App Store caches a lot of things for quite some while...

But I guess I can query them again just before purchase just to be sure and avoid any possible issues.

Hi again @Niano,

I get your thinking here. You just don't want any lag in showing IAP prices to the user in that screen, just in case there is no internet connection or there's a slight lag in getting the SKProductsResponse due to a slow internet connection. You therefore have all your IAP prices cached/stored already and can therefore display them immediately. I mean, this 'should' be fine. Especially if you don't plan to change your products and prices. But as you said, I would definitely query regardless when that screen is opened and just overwrite the stored values in the UI (nothing should happen if they are the same).

Also worth noting that if you're only making an SKProductsRequest at app launch, the last update may be much older than you expect. For instance, a user may not actually terminate your app for months... in which case, the SKProductsRequest also wouldn't be called again for months. Which is why it's always worth calling it every time your IAP products are displayed.

My app's UI is also made in a similar way - a dedicated VC for displaying my three IAPs, as well as being the place where the user makes the purchase of an auto-renewable subscription. I get around the problem by showing an alert to the user and dismissing the VC if there is no internet connection or the user is in a country/region I don't support. But also, my three IAP products are selectable (with one purchase button), so the prices are only displayed when the user selects one of them, by which time the SKProductsResponse should have been received and the prices are available.

See Fetching Product Information from the App Store and Loading In-App Product Identifiers that provides best practices on how to fetch product information in your apps.