iOS SDK
Integrate Appflow into your iOS app with the Swift SDK. Track events, manage subscriptions, display paywalls, and connect attribution data with just a few lines of code.
Requirements
iOS 15.0+Swift 5.7+Xcode 14+Installation
The recommended way to install the Appflow SDK is through Swift Package Manager. You can also use CocoaPods if your project requires it.
Swift Package Manager
In Xcode, go to File → Add Package Dependencies and enter the repository URL:
https://github.com/appflow-ai/appflow-swift-sdkCocoaPods
Alternatively, add the pod to your Podfile:
pod 'AppflowSDK', '~> 2.0'Configuration
Initialize the SDK as early as possible in your app lifecycle. If you are using SwiftUI, configure it in your @main App struct. For UIKit apps, use AppDelegate.
import Appflow
@main
struct MyApp: App {
init() {
Appflow.configure(
appId: "app_xxx",
apiKey: "ck_xxx",
options: AppflowOptions(
environment: .production,
logLevel: .info,
flushInterval: 30,
flushAt: 20
)
)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}Your appId and client key (ck_ prefix) are available in the Appflow dashboard under Settings → API Keys. The flushInterval controls how often batched events are sent (in seconds), and flushAt sets the batch size threshold.
Identify Users
Associate a known user with their events. Call identify once the user has signed in or when you have a stable user identifier. All subsequent events will be attributed to this user.
Appflow.identify(userId: "user_12345", properties: [
"email": "user@example.com",
"plan": "premium",
"signup_date": "2025-01-15"
])Track Events
Track custom events to understand user behavior. Events are batched locally and flushed according to your configuration. See the Event Tracking Guide for naming conventions and best practices.
// Simple event
Appflow.track("button_tapped")
// Event with properties
Appflow.track("purchase_started", properties: [
"product_id": "pro_monthly",
"price": "9.99",
"currency": "USD"
])
// Screen views
Appflow.trackScreen("Settings")Revenue Tracking
The SDK integrates directly with StoreKit 2 to automatically capture subscription and in-app purchase transactions. Enable it in your configuration, or report transactions manually for full control.
Automatic StoreKit 2 Tracking
import StoreKit
// Appflow automatically tracks StoreKit 2 transactions
// Just enable in configuration:
Appflow.configure(
appId: "app_xxx",
apiKey: "ck_xxx",
options: AppflowOptions(
trackStoreKitTransactions: true,
storeKitEnvironment: .production
)
)Manual Revenue Reporting
// Or manually report a transaction:
Appflow.trackRevenue(
productId: "pro_monthly",
priceCents: 999,
currency: "USD",
transactionId: "txn_abc123",
type: .subscription
)Paywalls
Powered by the Build Engine. Fetch remotely configured paywall layouts and present them with a single call. Paywall designs are managed in the Appflow dashboard and delivered over the air without app updates.
// Fetch paywall configuration
let paywall = try await Appflow.getPaywall("main_paywall")
// Show paywall UI
let result = await AppflowPaywallView(paywall: paywall).present()
switch result {
case .purchased(let product):
print("Purchased: \(product.id)")
case .restored:
print("Restored purchases")
case .dismissed:
print("User dismissed paywall")
}Attribution
Powered by the Acquire Engine. Pass attribution data from your Mobile Measurement Partner (MMP) so Appflow can connect ad spend to downstream revenue and compute ROAS.
// Set attribution data from your MMP
Appflow.setAttribution(
source: .appsFlyer,
data: [
"campaign": "summer_sale",
"adgroup": "lookalike_us",
"network": "meta"
]
)Push Notifications
Register the device for push notifications and let Appflow handle delivery tracking. Pass the APNs device token after the user grants permission.
// Register for push
Appflow.registerForPush(deviceToken: token)
// Handle received notification
Appflow.handlePushNotification(userInfo: notification.request.content.userInfo)Debug Mode
Enable verbose logging and an on-device event overlay during development. This helps verify that events, user properties, and revenue are tracked correctly before you ship to production.
#if DEBUG
Appflow.setLogLevel(.debug)
Appflow.enableDebugOverlay() // Shows event log overlay
#endif