SDK Configuration
Swift (iOS)
```swift
import RevenueCat
Purchases.logLevel = .debug
Purchases.configure(withAPIKey: "your_public_api_key", appUserID: "user_123")
```
Kotlin (Android)
```kotlin
Purchases.logLevel = LogLevel.DEBUG
Purchases.configure(PurchasesConfiguration.Builder(this, "your_public_api_key").build())
```
Flutter
```dart
await Purchases.setLogLevel(LogLevel.debug);
PurchasesConfiguration configuration = PurchasesConfiguration("your_public_api_key");
await Purchases.configure(configuration);
```
React Native
```javascript
Purchases.setLogLevel(Purchases.LOG_LEVEL.DEBUG);
Purchases.configure({ apiKey: "your_public_api_key" });
```
Checking Entitlements
Swift
```swift
let customerInfo = try await Purchases.shared.customerInfo()
if customerInfo.entitlements["pro"]?.isActive == true {
// User has premium access
}
```
Kotlin
```kotlin
Purchases.sharedInstance.getCustomerInfoWith(
onSuccess = { customerInfo ->
if (customerInfo.entitlements["pro"]?.isActive == true) {
// User has premium access
}
}
)
```
React Native
```javascript
const customerInfo = await Purchases.getCustomerInfo();
if (customerInfo.entitlements.active["pro"] !== undefined) {
// User has premium access
}
```
Fetching Offerings
Swift
```swift
Purchases.shared.getOfferings { (offerings, error) in
if let packages = offerings?.current?.availablePackages {
self.display(packages)
}
}
```
Kotlin
```kotlin
Purchases.sharedInstance.getOfferingsWith({ error -> }) { offerings ->
offerings.current?.availablePackages?.let { packages ->
// Display packages
}
}
```
Making a Purchase
Swift
```swift
Purchases.shared.purchase(package: package) { (transaction, customerInfo, error, userCancelled) in
if customerInfo.entitlements["pro"]?.isActive == true {
// Unlock premium content
}
}
```
Kotlin
```kotlin
Purchases.sharedInstance.purchase(
packageToPurchase = aPackage,
onError = { error, userCancelled -> },
onSuccess = { storeTransaction, customerInfo ->
if (customerInfo.entitlements["pro"]?.isActive == true) {
// Unlock premium content
}
}
)
```
Restoring Purchases
Swift
```swift
Purchases.shared.restorePurchases { customerInfo, error in
// Check customerInfo to see if entitlement is now active
}
```
Kotlin
```kotlin
Purchases.sharedInstance.restorePurchases(
onError = { error -> },
onSuccess = { customerInfo ->
// Check customerInfo to see if entitlement is now active
}
)
```
REST API - Get Customer Info
```bash
curl --request GET \
--url https://api.revenuecat.com/v1/subscribers/app_user_id \
--header 'Authorization: Bearer PUBLIC_API_KEY'
```