Article

Fetching Product Information from the App Store

Retrieve up-to-date information about the products for sale in your app to display to the user.

Overview

To make sure your users see only products that are actually available for them to purchase, query the App Store before displaying your app’s store UI. You will need a list of all of your app's product identifiers; for more on retrieving this list, see Loading In-App Product Identifiers.

Request Product Information

To query the App Store, create a products request (SKProductsRequest) and initialize it with a list of your product identifiers. Be sure to keep a strong reference to the request object; otherwise, the system might deallocate the request before it can complete.

The products request retrieves information about valid products, along with a list of the invalid product identifiers, and then calls its delegate to process the result. The delegate must implement the SKProductsRequestDelegate protocol to handle the response from the App Store. Here's a simple implementation of both pieces of code:

// Custom method.
- (void)validateProductIdentifiers:(NSArray *)productIdentifiers
{
    SKProductsRequest *productsRequest = [[SKProductsRequest alloc]
        initWithProductIdentifiers:[NSSet setWithArray:productIdentifiers]];

    // Keep a strong reference to the request.
    self.request = productsRequest;
    productsRequest.delegate = self;
    [productsRequest start];
}

// SKProductsRequestDelegate protocol method.
- (void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
    self.products = response.products;

    for (NSString *invalidIdentifier in response.invalidProductIdentifiers) {
        // Handle any invalid product identifiers.
    }

    [self displayStoreUI]; // Custom method.
}

Keep a reference to the array of product objects (SKProduct) returned to the delegate since you will need the corresponding product object to create a payment request when the user purchases a product. If the list of products sold on your app is subject to change, such as when you add or remove a product from sale, consider creating a custom class that encapsulates a reference to the product object along with other information, such as pictures or description text that you fetch from your server.

Troubleshoot Invalid Product IDs

Invalid product IDs in the App Store response to your products request usually indicate an error in your app’s list of product IDs. Invalid product IDs could also mean you configured the product improperly in App Store Connect. Actionable UI and insightful logging can help you resolve this type of issue more easily:

  • In production builds, fail gracefully by displaying the rest of your app’s store UI and omitting the invalid product.

  • In development builds, display an error to call attention to the issue.

  • In both production and development builds, use NSLog to write a message to the console so you have a record of the invalid identifier.

  • If your app fetched the list from your server, you could also define a logging mechanism to let your app send the list of invalid identifiers back to your server.

See Also

Retrieving Product Information

Loading In-App Product Identifiers

Load the unique identifiers for your in-app products in order to retrieve product information from the App Store.

SKProductsRequest

An object that can retrieve localized information from the App Store about a specified list of products.

SKProduct

Information about a product previously registered in App Store Connect.

SKProductsResponse

An App Store response to a request for information about a list of products.

SKProductSubscriptionPeriod

An object containing the subscription period duration information.

SKProductDiscount

The details of a discount offer for a subscription product.