Retrieve up-to-date information about the products for sale in your app to display to the user.
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 (
SKProducts) 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
SKProducts protocol to handle the response from the App Store. Here's a simple implementation of both pieces of code:
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
NSLogto 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.