Skip to main content

Fetching Products

Before fetching products from appmate, ensure that you created products by following Creating Products page.

Fetching Products from appmate#

This page describes how to fetch the products. With the getProducts method of appmate, you will get the active products synced with the App Store Connect.

If you have created some products for your app for the first time, it may take time to get synced products, as Apple has a time delay in activating the products.

After you called getProducts method, the products will be cached in the sdk for 10 minutes. So you will be able to get the response faster than getting directly from the network. If you add a new product and want to see it in your app for testing purposes, you can delete your app's cache. The products will be fetched from the network the next time you open your app. getProducts method returns products in the form of [Product]. If failed to fetch products resturns a GenericError.

You can access the list of all products, list of some spesific products or the list of products filtered by product types.

To handle the result of the asynchronous operation, you must specify a completion handler which provides the ([Product]?, GenericError?) -> Void. Completion handler is called when the query finishes successfully or with failure, as shown in the following code:

1. Fetching all products:#

Request#

Parameter NameType
completion([Product]?, GenericError?) -> Void

Response#

Parameter NameType
products[Product]?
errorGenericError?
PurchaseClient.shared.getProducts { products, error in    if let products = products {        print(products)    } else {        print(error)    }}

2. Fetching products by specifying a list of some productIds: #

When calling getProductsWithIdList, pass a productIdList that specifies a list of product ID strings created in the Creating Products page of our web console.

Request#

Parameter NameType
idList[String]
completion([Product]?, GenericError?) -> Void

Response#

Parameter NameType
products[Product]?
errorGenericError?
PurchaseClient.shared.getProductsWithIdList(["test_id1", "test_id2"]) { products, error in    if let products = products {        print(products)    } else {        print(error)    }}

3. Fetching products filtered by product types: #

When calling getProductsWithType, pass a type that specifies the type of products created in the Creating Products page of our web console.

Request#

Parameter NameType
typeString
completion([Product]?, GenericError?) -> Void

Response#

Parameter NameType
products[Product]?
errorGenericError?
PurchaseClient.shared.getProductsWithType("0") { products, error in    if let products = products {        print(products)    } else {        print(error)    }}

Displaying Products#

You can download the code of the sample client application from github and examine it.

fetch_products