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.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 03/26/2023 at 14:35
Last Updated on 03/27/2023 at 15:32
Three flowers that represent StoreKit, Swift and XCode side by side. Beneath them sits the text “Restore Purchases.”

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.

SubscribeFree Open-Source Apple StoreKit 2 Swift Project

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.

How to setup StoreKit in XcodeHow to create a StoreKit offering in XCode or App Store ConnectHow to create local offer codes for subscriptions in StoreKitHow to create, edit and delete offers in App Store ConnectFree iOS e-commerce Figma design fileHow to code and test StoreKit purchases in Swift and XCode

Step One: Implement the Utility

A screenshot of Xcode showing the code snippet that’s available below.

In XCode, create a new file and paste in the code below.

We recommend that you place it under Utils/StoreKit.

How to create a structured XCode project

Step Two: Implement the code

A screenshot of Xcode showing the code snippet that’s available below.

In your app, wherever you wish to allow users to restore purchases, add the code below.

How to use async and await in Swift projects

Step Three: Verify

A screenshot of an iOS app showing the restore purchases alert that appears when you verify that the code in this tutorial works.

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.

Read Apple StoreKit 2 Development Guide

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe