How to code and test restore purchases in Swift and Xcode
A step by step guide on implementing and testing code that enables customers to restore purchases for In-App Purchases or Subscriptions in an App.
The guide was made using our Free iOS StoreKit 2 Open Source project which is recommended for developers or business folk wishing to learn about how In-App Purchases or Subscriptions work and the code behind them.
If you wish to learn more about how to setup StoreKit, create a StoreKit offering, create custom offer codes, design a UI that considers all StoreKit scenarios or make StoreKit product purchases.
Step One: Implement the Utility
In XCode, create a new file and paste in the code below.
We recommend that you place it under Utils/StoreKit.
Step Two: Implement the code
In your app, wherever you wish to allow users to restore purchases, add the code below.
Step Three: Verify
Run the app and test the functionality. It should pop up an alert similar to the one above.
Looking to learn more about developing apps with StoreKit 2?
Read our comprehensive development guide linked below to learn about all the secrets behind developing In-App Purchases and Subscriptions with StoreKit 2.