To start with, go to App Store Connect, go to your application page and click on "Manage" for in-app purchases.
There you can see a list of the products defined in your application. Find the ones you want to use for testing, then click one one to load product details:
Open your application project in Xcode and create a new StoreKit Configuration File.
You can choose whatever name you like and save it into your project; if desired you could even have multiple StoreKit Configuration files.
Do not add it to the project on creation; it actually gets set up in the application Scheme as we'll see shortly.
The configuration .storekit file will be added to your project navigation, where you can then select it to edit.
When you have the configuration open for editing, use the "+" button to add the product you pulled up the definition for in App Store Connect.
You can choose whatever type of product you have, in this example case I'll add a subscription product.
As a first step because I've not added a subscription product before, it will ask for a subscription group - it's a good practice to name this group the same as you have in your App Store Connect product:
Now we have a new product with a temporary name, ID, and price.
The most important thing to change is to edit the product ID to match what you have in App Store Connect since your code will be expecting a product with a specific product ID, as I've done with this example product:
You can enter as many products as you like.
Now that we have a StoreKit configuration file, how can we make use of it? In the top menu bar target dropdown, select "Edit Scheme".
When you select Edit Scheme, you'll be able to select the configuration file you just created for the "StoreKit Configuration" entry.
When you activate this configuration, it will stay enabled for any change in simulator or device you select to run on. Note that it will not have any effect on pre-iOS 14 simulators or devices, it needs iOS 14 to take effect.
Side note: After adding this Configuration to the scheme, the project will still load and work in older versions of Xcode but they may revert or clear the chosen StoreKit configuration.
Now when I run on an iOS 14 simulator I see the product I added on my payment screen:
Note that in this case the paywall is showing only the product I entered correctly, that's also the only one that would work for any purchase attempts that used StoreKit to purchase. The others are products the paywall knows should be there, but provides only placeholder values for since it can find only one of the three products desired.
Testing Best Practice
Keep the number of products defined in your StoreKit configuration file small so it's easier to keep up with App Store Connect changes.
When testing with a StoreKit configuration file enabled, you are not using a Sandbox account. If you want to run a device build with a Sandbox account, simply de-select the StoreKit config in the application Scheme.
While editing the StoreKit Config file, you can now access advanced purchase testing options.
Allows you to change which country the purchase is simulated to occur in.
Controls which localization will be used to display product details.
For subscriptions, lets you specify an acceleration of time so subscriptions expire more quickly for testing. Unlike traditional device Sandbox testing, you have a range of acceleration options to choose from.
Enable Interrupted Purchases
Simulates a user who runs into billing issues during a purchase.
Allow you to produce failure transactions that may occur in StoreKit when dealing with subscription winback offers, so you can see how your application responds to different error scenarios.
Enable Ask To Buy
Simulates the experience of purchasing on a device that has Ask to Buy enabled, as would happen if a parent was controlling purchases on a device.
Subscription Offers Keys
Save Public Certificate
For testing winback offers, a key needed to generate an offer.
Updated over 1 year ago