Skip to main content

SDK Quickstart

This guide will walk you through how to get up and running with subscriptions and RevenueCat's SDK with only a few lines of code.

1. Set up your RevenueCat account

Before continuing with this guide, follow our Setting up RevenueCat guide to create a free account and set up your first project.

Set up your account →

2. Product Configuration

Store Setup

Before you can start using RevenueCat to fetch products, you must configure your products in the respective stores. See the following guides for App Store Connect, Google Play Console, Amazon Appstore, and Stripe for help navigating through this process.

If you are selling iOS products, be sure to sign your 'Paid Applications Agreement' and fill out your bank and tax information in App Store Connect > Agreements, Tax, and Banking. This needs to be completed before you can test any purchases.

📘Want to skip the store setup while testing?

On iOS, you can delay configuring products in App Store Connect by testing with StoreKit Configuration files instead. These config files require minimal setup and are configurable via Xcode directly.

Read more about setting up StoreKit Configuration files in our Sandbox Testing guide.

Configure Products and Entitlements in RevenueCat

Once your in-app products have been configured in App Store Connect, Google Play Console, Amazon Appstore, or Stripe, you'll need to copy that configuration into the RevenueCat dashboard. RevenueCat uses an Entitlements system to control access to premium features, and Offerings to manage the set of products you offer to customers.

Entitlements are the level of access that a customer is "entitled" to after purchasing a specific product, and Offerings is a simple way for you to organize the in-app products you wish to "offer" on your paywall and configure them remotely. We recommend utilizing these features to simplify your code and enable you to change products without releasing an app update.

See Configuring Products to set up your products and then organize them into Offerings or Entitlements.

Offerings Diagram

Build and Design Your Paywall

After configuring your offerings, you can jump right into designing a paywall (even before installing the SDK!) by choosing Paywalls in the sidebar of your project dashboard.

RevenueCat provides several pre-built, customizable paywall templates that you can use to rapidly create a paywall.

If you'd prefer to install the SDK before designing your paywall, you can always come back to this step later.

Create a Paywall →

Want to build your own custom paywall? See Displaying Products, Making Purchases, and Restoring Purchases for more information on manual implementation.

3. Using RevenueCat's Purchases SDK

Our SDK seamlessly implements purchases and subscriptions across platforms while syncing tokens with the RevenueCat server.

SDK Installation

Install the SDK on your preferred platform.

Note: if you are using RevenueCat's Paywalls, the RevenueCatUI package is required during the installation process.

If you run into issues with the SDK, see Troubleshooting the SDKs for guidance.

SDK Installation Guides →

Initialize and Configure the SDK

📘Only use your public SDK key to configure Purchases

You can get your public SDK key from the API keys tab under Project settings in the dashboard.

You should only configure the shared instance of Purchases once, usually on app launch. After that, the same instance is shared throughout your app by accessing the .shared instance in the SDK.

See our guide on Configuring SDK for more information and best practices.

Make sure you configure Purchases with your public SDK key only. This API key can be found in the API Keys Project settings page. You can read more about the different API keys available in our Authentication guide.

// on iOS and tvOS, use `application:didFinishLaunchingWithOptions:`
// on macOS and watchOS use `applicationDidFinishLaunching:`

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

Purchases.logLevel = .debug
Purchases.configure(withAPIKey: <revenuecat_project_apple_api_key>, appUserID: <app_user_id>)

}

The app_user_id field in .configure is how RevenueCat identifies users of your app. You can provide a custom value here or omit it for us to generate an anonymous id. For more information, see our Identifying Users guide.

When in development, we recommend enabling more verbose debug logs. For more information about these logs, see our Debugging guide.

If you're planning to use RevenueCat alongside your existing purchase code, be sure to tell the SDK that your app will complete the purchases

📘Configuring Purchases with User IDs

If you have a user authentication system in your app, you can provide a user identifier at the time of configuration or at a later date with a call to .logIn(). To learn more, check out our guide on Identifying Users.

Present a Paywall

At this point, you're ready to present a paywall to your users. If you skipped the paywall setup earlier, that's okay! The SDK will display a default, non-customized paywall. If you want to customize a paywall first, head back up to the Build and Design Your Paywall section.

The SDK will automatically fetch the configured Offerings and retrieve the product information from Apple, Google, or Amazon. Thus, available products will already be loaded when customers launch your paywall.

Presenting a paywall varies depending on your platform. See Displaying Paywalls to see in-depth examples for each platform.

Present a Paywall →

Want to display your products manually? See Displaying Products.

SDK not fetching products or offerings?

A common issue when displaying your paywall or making a purchase is missing or empty offerings. This is almost always a configuration issue.

If you're running into this error, please see our community post for troubleshooting steps.

Make a Purchase

Once your paywall is presented, select one of your products to make a purchase. The SDK will handle the purchase flow automatically and send the purchase information to RevenueCat. The RevenueCat SDK will automatically handle sandbox vs. production environments.

Each platform requires slightly different configuration steps to test in sandbox. See Sandbox Testing for more information.

When the purchase is complete, you can find the purchase associated to the customer in the RevenueCat dashboard. You can search for the customer by their App User ID that you configured, or by the automatically assigned $RCAnonymousID that you'll find in your logs.

Note: RevenueCat always validates transactions with the respective store. The dashboard will only reflect purchases that have been successfully validated by the store.

Additionally, the SDK will automatically update the customer's CustomerInfo object with the new purchase information. This object contains all the information about the customer's purchases and subscriptions.

Want to manually call the purchase method? See Making Purchases.

Check Subscription Status

The SDK makes it easy to check what active subscriptions the current customer has, too. This can be done by checking a user's CustomerInfo object to see if a specific Entitlement is active, or by checking if the active Entitlements array contains a specific Entitlement ID.

If you're not using Entitlements (you probably should be!) you can check the array of active subscriptions to see what product IDs from the respective store it contains.

// Using Swift Concurrency
let customerInfo = try await Purchases.shared.customerInfo()
if customerInfo.entitlements.all[<your_entitlement_id>]?.isActive == true {
// User is "premium"
}
// Using Completion Blocks
Purchases.shared.getCustomerInfo { (customerInfo, error) in
if customerInfo?.entitlements.all[<your_entitlement_id>]?.isActive == true {
// User is "premium"
}
}

You can use this method whenever you need to get the latest status, and it's safe to call this repeatedly throughout the lifecycle of your app. Purchases automatically caches the latest CustomerInfo whenever it updates — so in most cases, this method pulls from the cache and runs very fast.

It's typical to call this method when deciding which UI to show the user and whenever the user performs an action that requires a certain entitlement level.

📘Here's a tip!

You can access a lot more information about a subscription than simply whether it's active or not. See our guide on Subscription Status to learn if subscription is set to renew, if there's an issue detected with the user's credit card, and more.

Reacting to Subscription Status Changes

You can respond to any changes in a customer's CustomerInfo by conforming to an optional delegate method, purchases:receivedUpdated:.

This method will fire whenever the SDK receives an updated CustomerInfo object from calls to getCustomerInfo(), purchase(package:), purchase(product:), or restorePurchases().

Note: CustomerInfo updates are not pushed to your app from the RevenueCat backend, updates can only happen from an outbound network request to RevenueCat, as mentioned above.

Depending on your app, it may be sufficient to ignore the delegate and simply handle changes to customer information the next time your app is launched or in the completion blocks of the SDK methods.

// Additional configure setup
// on iOS and tvOS, use `application:didFinishLaunchingWithOptions:`
// on macOS and watchOS use `applicationDidFinishLaunching:`

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

Purchases.logLevel = .debug
Purchases.configure(withAPIKey: <revenuecat_api_key>)
Purchases.shared.delegate = self // make sure to set this after calling configure

return true
}

extension AppDelegate: PurchasesDelegate {
func purchases(_ purchases: Purchases, receivedUpdated customerInfo: CustomerInfo) {
/// - handle any changes to the user's CustomerInfo
}
}

Restore Purchases

RevenueCat enables your users to restore their in-app purchases, reactivating any content that they previously purchased from the same store account (Apple, Google, or Amazon account). We recommend that all apps have some way for users to trigger the restore method. Note that Apple does require a restore mechanism in the event a user loses access to their purchases (e.g: uninstalling/reinstalling the app, losing their account information, etc).

By default, RevenueCat Paywalls include a 'Restore Purchases' button. You can also trigger this method programmatically.

Purchases.shared.restorePurchases { customerInfo, error in
// ... check customerInfo to see if entitlement is now active
}

If two different App User IDs restore transactions from the same underlying store account (Apple, Google, or Amazon account) RevenueCat may attempt to create an alias between the two App User IDs and count them as the same user going forward. See our guide on Restoring Purchases for more information on the different configurable restore behaviors.

👍You did it!

You have now implemented a fully-featured subscription purchasing system without spending a month writing server code. Congrats!

Sample Apps

To download more complete examples of integrating the SDK, head over to our sample app resources.

View Sample Apps →

Next Steps