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.

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.

Note: If you're using a hybrid SDK, such as React Native or Flutter, you'll need to initialize the SDK with a separate API key for each platform (i.e., iOS and Android). The keys can be found in the RevenueCat dashboard under Project Settings > API keys > App specific keys.

import RevenueCat

@main
struct SampleApp: App {
init() {
Purchases.logLevel = .debug
Purchases.configure(withAPIKey: <public_apple_api_key>, appUserID: <app_user_id>)
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Enabling Debug Logsโ€‹

Be sure to enable and view debug logs while implementing the SDK and testing your app. Debug logs contain important information about what's happening behind the scenes and should be the first thing you check if your app is behaving unexpectedly.

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โ€‹

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, RevenueCat will generate an anonymous App User 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.

Proxies & configuration for users in Mainland Chinaโ€‹

Weโ€™ve received reports of our API being blocked in mainland China.

While we work on a long-term solution, if your app has a significant user base in this region, set the proxyURL property to https://api.rc-backup.com/ before initializing the RevenueCat SDK. Ensure this configuration occurs prior to SDK setup to prevent connection issues for users in mainland China.

๐Ÿ“˜If you already have a proxy server

If you have your own proxy server and already use the proxyURL API, you don't need any further configuration.

Purchases.proxyURL = URL(string: "https://api.rc-backup.com/")!

iOSโ€‹

Listening for CustomerInfo updatesโ€‹

๐Ÿ“˜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 on the current device.

Implement the following delegate method to receive updates to the CustomerInfo object:

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).

Handling Promoted Purchasesโ€‹

Implement the following delegate method to handle promoted purchases:

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โ€‹

Listening for CustomerInfo updatesโ€‹

๐Ÿ“˜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 on the current device.

Implement the following listener to receive updates to the CustomerInfo object:

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).

Next stepsโ€‹

Once you've configured the SDK, it's time to add your products in the dashboard.

Add your products โ†’