# RevenueCat Integration Guide - SelfieCam
This document describes the RevenueCat integration for SelfieCam and what needs to be configured for production.
## Current Configuration
### API Key Setup
SelfieCam uses xcconfig files to manage RevenueCat API keys, with the key injected into Info.plist at build time.
**File Structure:**
```
SelfieCam/
├── Info.plist # Contains $(REVENUECAT_API_KEY) substitution
├── SelfieCam/
│ └── Configuration/
│ ├── Base.xcconfig # Shared settings
│ ├── Debug.xcconfig # Includes Secrets.debug.xcconfig
│ ├── Release.xcconfig # Includes Secrets.release.xcconfig
│ ├── Secrets.debug.xcconfig # Test API key (gitignored)
│ └── Secrets.release.xcconfig # Production API key (gitignored)
```
**Current Keys:**
- **Debug**: `test_mImwoNKwfgZcUNQuBLBuVPqSHBR` (configured ✅)
- **Release**: `appl_YOUR_PRODUCTION_KEY_HERE` (needs replacement ❌)
### PremiumManager
Located at: `SelfieCam/Shared/Premium/PremiumManager.swift`
- Reads API key from `Bundle.main.object(forInfoDictionaryKey: "RevenueCatAPIKey")`
- Entitlement identifier: `"Selfie Cam by TopDog Pro"`
- Supports debug premium toggle via UserDefaults
---
## Before Release Checklist
### 1. Replace Production API Key
Edit `SelfieCam/Configuration/Secrets.release.xcconfig`:
```
// Current (placeholder):
REVENUECAT_API_KEY = appl_YOUR_PRODUCTION_KEY_HERE
// Replace with your production key from RevenueCat:
REVENUECAT_API_KEY = appl_your_actual_production_key
```
Get the production key from: **RevenueCat Dashboard → Project Settings → API Keys → Public App-Specific API Key**
### 2. Verify Entitlement Identifier
The entitlement identifier in `PremiumManager.swift` must match exactly what's in RevenueCat:
```swift
private let entitlementIdentifier = "Selfie Cam by TopDog Pro"
```
Verify this matches: **RevenueCat Dashboard → Entitlements → Your Entitlement Name**
### 3. Configure App Store Connect
- [ ] Products created with correct IDs
- [ ] Subscription group configured
- [ ] Paid Apps agreement accepted
- [ ] Bank and tax info submitted
### 4. Configure RevenueCat Dashboard
Follow these steps at [app.revenuecat.com](https://app.revenuecat.com):
#### Step 1: Create Project and App
1. Create a new project (or use existing)
2. Add iOS app with bundle ID: `com.mbrucedogs.SelfieCam`
#### Step 2: Connect to App Store
1. Go to **App Store Connect** → **Users and Access** → **Integrations** → **App-Specific Shared Secrets**
2. Generate a new shared secret for SelfieCam
3. In RevenueCat: **Project Settings** → **Apps** → **Selfie Cam** → Add the shared secret
#### Step 3: Create Products
1. Go to **Products** → **+ New**
2. Add each product with IDs matching App Store Connect exactly:
- Example: `com.mbrucedogs.SelfieCam.pro.monthly`
- Example: `com.mbrucedogs.SelfieCam.pro.yearly`
- Example: `com.mbrucedogs.SelfieCam.pro.lifetime`
#### Step 4: Create Entitlement
1. Go to **Entitlements** → **+ New**
2. Create entitlement with identifier: `Selfie Cam by TopDog Pro`
3. Attach all products that should grant this entitlement
#### Step 5: Create Offering
1. Go to **Offerings** → Edit **default** offering
2. Add packages:
- `$rc_monthly` → your monthly product
- `$rc_annual` → your yearly product
- `$rc_lifetime` → your lifetime product
#### Step 6: Design Paywall (Optional)
1. In your offering, click **Add Paywall**
2. Use the visual editor to design
3. Configure colors, text, layout to match SelfieCam branding
#### Step 7: Get API Keys
Go to **Project Settings** → **API Keys**:
- **Test Key** (starts with `test_`): Already configured in `Secrets.debug.xcconfig`
- **Production Key** (starts with `appl_`): Copy this to `Secrets.release.xcconfig`
---
## Testing
### Debug Premium Toggle
In debug builds, you can enable premium without purchasing:
1. Go to Settings in the app
2. Toggle "Debug Premium" (only visible in DEBUG builds)
### Sandbox Testing
1. Create Sandbox Tester in App Store Connect
2. Sign out of App Store on device
3. Make purchase, sign in with sandbox credentials
4. Verify in RevenueCat dashboard
---
## Troubleshooting
### "RevenueCat API key not configured"
1. Clean build: `rm -rf ~/Library/Developer/Xcode/DerivedData/SelfieCam-*`
2. Verify xcconfig includes are correct (relative paths)
3. Check `Info.plist` contains `RevenueCatAPIKey$(REVENUECAT_API_KEY)`
4. Verify with: `plutil -p ~/Library/Developer/Xcode/DerivedData/SelfieCam-*/Build/Products/Debug-*/Selfie\ Cam.app/Info.plist | grep Revenue`
### Products Not Loading
1. Verify product IDs match exactly (case-sensitive)
2. Check API key is correct for environment
3. Ensure shared secret is configured in RevenueCat
4. Wait a few minutes after creating new products
---
## Related Documentation
- [IN_APP_PURCHASE_SETUP.md](IN_APP_PURCHASE_SETUP.md) - Detailed App Store Connect setup
- [RevenueCat Docs](https://docs.revenuecat.com) - Official documentation