Guide to creating a StoreKit configuration file
To be able to test in-app purchases without needing to configure the products in App Store Connect, it is necessary to create a StoreKit configuration file. With this file, we simulate the products that in production will be provided by Apple’s servers. Let’s see how to set up our StoreKit configuration file.
Creating the StoreKit Configuration File
To create this file, go to File > New > File from Template. Here, look for StoreKit Configuration File.
Once selected, follow the steps to create your configuration file, name it, and save it in your project.
Now open your file and create an Auto-Renewable Subscription.
You can create any type of subscription or product; for this example, we select Auto-Renewable Subscription
Follow the steps, first by creating a group — in our case, it will be “AsyncLearnPro” — and then create your subscription, adding a reference name and an ID.
For our example, we will need at least two subscriptions. So, follow the steps again to create a new subscription, but this time, instead of creating a new group, use the group we created earlier.
Now edit the price and the period of each of your subscriptions to your liking.
Finally, to finish setting up our products, update the localization of our products. For both subscriptions, go to the end and add a localization.
Using Our Configuration File
To use our configuration file, we need to edit our scheme. In Options, select our file in the StoreKit Configuration section.
Now, let’s create our subscription view using the products we previously configured.
import SwiftUI
//1
import StoreKit
struct ContentView: View {
var body: some View {
//2
SubscriptionStoreView(productIDs: ["com.asynclearn.monthly", "com.asynclearn.yearly"]) {
Text("Unlock Pro")
}
}
}
- We import
StoreKit
.
2. We create the SubscriptionStoreView
view, adding an array with the IDs of the products we created in our configuration file.