Skip to main content

Configuring the SDK

If this is your first time integrating RevenueCat into your app, we recommend following our Quickstart guide.

📘Using an older SDK (v3.x)

View our migration guide to v4.x here.

Basic Configuration

Initialization

Once you've installed the SDK for your app, it's time to initialize and configure it.

You should only configure Purchases once, usually early in your application lifecycle. After configuration, the same instance is shared throughout your app by accessing the .shared instance in the SDK.

Make sure you configure Purchases with your public SDK key only. You can read more about the different API keys available in our Authentication guide.

import RevenueCat

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

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

}
❗️iOS 15+ Prewarming

In certain cases, calling configure in application:didFinishLaunchingWithOptions: should be avoided. See Identifying Users for more information.

📘SwiftUI App Protocol

Using SwiftUI's App protocol? Check out our resource on setting up the Purchases SDK with SwiftUI.

Enabling Debug Logs

Be sure to enable and view debug logs before filing a ticket with RevenueCat Support.

As detailed in the sample code above, debug logs can be enabled or disabled by setting the Purchases.logLevel property before configuring Purchases.

Debug logs will provide detailed log output in Xcode or LogCat for what is going on behind the scenes and should be the first thing you check if your app is behaving unexpectedly, and also to confirm there aren't any unhandled warnings or errors.

Additional Configuration Options

The SDK allows additional configuration on first setup:

  • API Key (required): The public API key that corresponds to your app, found via Project Settings > API keys > App specific keys in the RevenueCat dashboard.
  • App User ID (optional): An identifier for the current user. Pass null if you don't have a user identifier at the time of configuration and RevenueCat will generate an anonymous Id for you. See our guide on identifying users for more information.
  • Purchases Completed By (optional): A boolean value to tell RevenueCat not to complete purchases. Only set purchase completion to your app if you have your own code handling purchases.
  • User Defaults (optional, iOS only): A key to override the standard user defaults used to cache CustomerInfo. This is required if you need to access CustomerInfo in an iOS App Extension.

Advanced Configuration

Additional configuration options on the .shared instance of Purchases.

iOS

Delegates

DELEGATE purchases:receivedUpdated

Called whenever Purchases receives an updated CustomerInfo object. This may happen periodically throughout the life of the app if new information becomes available (e.g. after making a purchase).

📘

Note: RevenueCat doesn't push new data to the SDK, so this method is only called when CustomerInfo is updated from another SDK method or after a purchase is made.


DELEGATE purchases:readyForPromotedProduct

Called when a user initiates a promoted in-app purchase from the App Store. If your app is able to handle a purchase at the current time, run the defermentBlock in this method. If the app is not in a state to make a purchase: cache the defermentBlock, then call the defermentBlock when the app is ready to make the promoted purchase. If the purchase should never be made, you don't need to ever call the defermentBlock and Purchases will not proceed with promoted purchases.

Android

Listeners

LISTENER UpdatedCustomerInfoListener

Called whenever Purchases receives an updated CustomerInfo object. This may happen periodically throughout the life of the app if new information becomes available (e.g. after making a purchase).

📘

Note: RevenueCat doesn't push new data to the SDK, so this method is only called when CustomerInfo is updated from another SDK method or after a purchase is made.

⚠️NodeJS

There is no way to import RevenueCat into NodeJS, we don't make any such modules or sdks. The best option is to use our APIs directly using Node fetch. In our API docs you should use our JavaScript language to do so.