# How to add subscriptions to a Swift app

Tom Brewer
Table of Contents

These notes are based on the YouTube video by RevenueCat


Implementing In-App Subscriptions with RevenueCat

Prerequisites

To follow along with this tutorial, you’ll need:

  • A RevenueCat account
  • An app configured in the App Store Connect
  • An app configured in RevenueCat
  • Configured products in App Store Connect
  • A sandbox tester account

Configuring RevenueCat

Before implementing in-app subscriptions, you need to configure RevenueCat. This involves:

  • Creating a product in RevenueCat that matches the configuration in App Store Connect
  • Configuring an offering, which is a set of products or a package presented to the user
  • Configuring an entitlement, which represents access levels tied to products; full setup involves groups in App Store Connect

Adding RevenueCat to Your Project

To add RevenueCat to your project, you’ll need to:

  • Use the Swift Package Manager to add the RevenueCat package
  • Import RevenueCat in your files
  • Configure your API key in a constants file or directly in code, and set up entitlements in the RevenueCat dashboard

Configuring the App Delegate

In the app delegate, you’ll need to:

  • Set the log level for RevenueCat
  • Configure the SDK with your API key and store kit
  • Add a purchases delegate to update your UI based on subscription status
// Configure RevenueCat
Purchases.configure(with: Configuration.Builder()
.with(apiKey: Constants.apiKey)
.with(storeKit2IfAvailable: true)
.build())

As you work on implementing in-app subscriptions, you may also want to explore other ways to build and automate your iOS apps, such as using Claude Code to streamline your development process.

Getting Offerings and Products

To get offerings and products, you’ll need to:

  • Use the getOfferings method from RevenueCat
  • Handle errors and update your UI accordingly
// Get offerings
Purchases.shared.getOfferings { (offerings, error) in
if let error = error {
print(error.localizedDescription)
} else if let offerings = offerings {
// Update your UI with the offerings
}
}

🔗 See Also: How to Build AI Systems That Actually Run Your Business (Not Just Chat)

Handling Purchases

To handle purchases, you’ll need to:

  • Use the purchase method from RevenueCat, preferably with a product from an offering
  • Handle errors and update your UI accordingly
// Handle purchases
Purchases.shared.purchase(product: product) { (transaction, error) in
if let error = error {
print(error.localizedDescription)
} else if let transaction = transaction {
// Update your UI with the transaction
}
}

Building on the concepts of AI-powered business systems, you can also learn from How I Get AI To Follow My Designs (In-Depth Walkthrough) to improve your app’s overall user experience.

Restoring Purchases

To restore purchases, you’ll need to:

  • Use the restorePurchases method from RevenueCat
  • Handle errors and update your UI accordingly
// Restore purchases
Purchases.shared.restorePurchases { (customerInfo, error) in
if let error = error {
print(error.localizedDescription)
} else if let customerInfo = customerInfo {
// Update your UI with the customer info
}
}

User Identifier and Subscription Status

To get the user identifier and subscription status, you’ll need to:

  • Use the getCustomerInfo method from RevenueCat
  • Handle errors and update your UI accordingly
// Get customer info
Purchases.shared.getCustomerInfo { (customerInfo, error) in
if let error = error {
print(error.localizedDescription)
} else if let customerInfo = customerInfo {
// Update your UI with the customer info
}
}

💡 Related: 5 Claude Code MCP Servers You Need To Be Using

Summary

Implementing in-app subscriptions with RevenueCat involves configuring your app, adding RevenueCat to your project, configuring the app delegate, getting offerings and products, handling purchases, restoring purchases, and getting the user identifier and subscription status. By following these steps, you can easily add in-app subscriptions to your Swift app using RevenueCat.

For a full and accurate configuration example, consider the following initialization code:

init() {
Purchases.configure(withAPIKey: "api_key")
}

Or with a builder for more options:

Purchases.configure(with: Configuration.Builder()
.with(apiKey: Constants.apiKey)
.with(storeKit2IfAvailable: true)
.build())
Tom Brewer Avatar

Thanks for reading my notes! Feel free to check out my other notes or contact me via the social links in the footer.

# Frequently Asked Questions

What are the prerequisites for implementing in-app subscriptions in an iOS app using Swift and RevenueCat?

To implement in-app subscriptions, you need a RevenueCat account, an app configured in the App Store Connect, an app configured in RevenueCat, configured products in App Store Connect, and a sandbox tester account. These prerequisites are essential for a successful integration. You can sign up for a RevenueCat account and get your API key at revenuecat.com. Additionally, you can find a sample app on GitHub to follow along with the tutorial.

How do I add RevenueCat to my iOS project and configure it for in-app subscriptions?

To add RevenueCat to your project, use the Swift Package Manager to add the RevenueCat package and import it in your files. Then, configure your API key in a constants file or directly in code and set up entitlements in the RevenueCat dashboard. You can use the Purchases.configure method to configure RevenueCat with your API key and store kit.

What is the purpose of configuring offerings and products in RevenueCat, and how do I get them in my app?

Configuring offerings and products in RevenueCat allows you to present a set of products or packages to the user. To get offerings and products in your app, use the getOfferings method from RevenueCat and handle errors and updates to your UI accordingly. You can then use the retrieved offerings to update your UI and provide users with available subscription options.

How do I handle purchases and restore purchases in my iOS app using RevenueCat?

To handle purchases, use the purchase method from RevenueCat, preferably with a product from an offering. To restore purchases, use the restorePurchases method and handle errors and updates to your UI accordingly. These methods allow you to provide a seamless subscription experience for your users.

Why is it important to configure the app delegate and set the log level for RevenueCat in my iOS app?

Configuring the app delegate and setting the log level for RevenueCat is essential for a successful integration. This allows you to configure the SDK with your API key and store kit, add a purchases delegate to update your UI based on subscription status, and troubleshoot any issues that may arise during the integration process.

What is the purpose of getting the user identifier and subscription status in my iOS app using RevenueCat?

Getting the user identifier and subscription status allows you to provide a personalized experience for your users and update your UI accordingly. You can use the getCustomerInfo method from RevenueCat to retrieve this information and handle errors and updates to your UI as needed.

Continue Reading