Apple just released Xcode 12 and iOS 14. This release includes great new features for in-app purchases which we’ve discussed here. With iOS 14 now live for your customers, there are some very important changes to how you need to test and develop your app with StoreKit and IAPs. In this article, we provide an overview of important changes to testing purchases in the iOS 14 simulators.
If you've installed Xcode 12 and run anything using StoreKit in an iOS 14 simulator, you may have noticed a problem - StoreKit products you set up on AppStoreConnect no longer load, so any purchase pages you set up may be blank!
App running in iOS 13.2 simulator from Xcode 12. Products still appear.
Now, iOS 13 simulators will still work as you are used to, as will sandbox testing on device (with some enhancements which we'll get into in future articles). You'll likely want to continue testing on iOS 14 simulators as well, so how can we get our products back?
The answer: migrate our existing App Store Connect product definitions to a StoreKit configuration file for Xcode12
There you can see a list of the products defined in your application. Find the ones you want to use for testing, then click on one to load product details:
Open your application project in Xcode 12 and create a new StoreKit Configuration:
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 previously had selected in App Store Connect:
At this step, choose the type of product that you have set up in App Store Connect, either consumable, non-consumable, or auto-renewable subscription in-app purchase. In this example case I'll add an auto-renewable 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 alter the product ID to match what you have in AppStoreConnect 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.
Also it is worth noting that 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 my case my payment screen 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 in the StoreKit configuration.
To keep testing simple you may want to keep the number of products defined in a StoreKit configuration minimal so it's easier to track with App Store Connect changes, or you can exactly duplicate your full product set.
In the case of subscription testing in the simulator, because you can select custom time acceleration you could use any subscription duration and have it expire quickly if you wished - that and more will be talked about in more detail in a future article.
Note that this StoreKit configuration you've enabled in the Scheme will also be used on an iOS 14 device, and you'll not be using a sandbox account. If you want to run a device build and still use a Sandbox account for testing, simply deselect the StoreKit Configuration in the application Scheme.
Google Play Billing Library v5, subscription offers, LiveOps events, prepaid subscriptions & everything you need to know about IAPs and from Google I/O.
We shipped a new SwiftUI app, offering a lifetime IAP and two subscriptions plans powered by Nami. See how to do it.