Integrate the iOS SDK
The iOS SDK initializes with a configuration object, identifies users, sends events, and can present flows (paywalls). Events power segments and workflows; workflows decide when to show a flow.
Snippets match the current SDK in
/Users/levi/dev/nuxie-ios
. Adjust paths and structure for your app.
Install
bash
# Swift Package Manager
# Xcode → File → Add Package Dependencies…
# Package URL:
https://github.com/nuxieio/nuxie-ios
Initialize
swift
import Nuxie
// SwiftUI App example
@main
struct MyApp: App {
init() {
var config = NuxieConfiguration(apiKey: "NX_…")
config.environment = .production // or .staging / .development
config.logLevel = .info
do { try NuxieSDK.shared.setup(with: config) }
catch { print("Nuxie setup failed: \(error)") }
}
var body: some Scene { WindowGroup { ContentView() } }
}
// UIKit AppDelegate example
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
let config = NuxieConfiguration(apiKey: "NX_…")
config.environment = .production
config.logLevel = .warning
do { try NuxieSDK.shared.setup(with: config) }
catch { print("Nuxie setup failed: \(error)") }
return true
}
}
Identify a user after login (optional but recommended):
swift
NuxieSDK.shared.identify(
"user_123",
userProperties: ["plan": "free"],
userPropertiesSetOnce: ["signup_at": Date()]
)
Send events
Events are lightweight name + properties. They can trigger workflows and unlock segments.
swift
// Fire-and-forget
NuxieSDK.shared.track("app_opened")
// With properties
NuxieSDK.shared.track("viewed_paywall", properties: [
"placement": "home_top_banner"
])
// Observe immediate outcomes (e.g., if a flow shows instantly)
NuxieSDK.shared.track("purchase_completed", properties: [
"sku": "pro_annual",
"price": 59.99,
"currency": "USD"
]) { result in
switch result {
case .noInteraction:
break
case .flow(let completion):
print("Flow \(completion.flowId) outcome: \(completion.outcome)")
case .failed(let error):
print("Track failed: \(error)")
}
}
Present a flow (paywall)
Workflows typically present flows automatically when rules match. For manual control or debugging:
swift
// Show a specific flow by ID
@MainActor
try await NuxieSDK.shared.showFlow(with: "paywall_summer_launch")
// Or get a UIViewController to present yourself (debug)
@MainActor
let vc = try await NuxieSDK.shared.getFlowViewController(with: "paywall_summer_launch")
present(vc, animated: true)
If you manage purchases, implement a NuxiePurchaseDelegate
and assign it on the configuration:
swift
final class MyPurchaseDelegate: NuxiePurchaseDelegate {
func purchase(_ product: any StoreProductProtocol) async -> PurchaseResult { .success }
func restore() async -> RestoreResult { .noPurchases }
}
var config = NuxieConfiguration(apiKey: "NX_…")
config.purchaseDelegate = MyPurchaseDelegate()
try NuxieSDK.shared.setup(with: config)
Debugging
- Run a Debug build and monitor console logs.
- Manually present a flow to isolate UI from workflow targeting.
- Confirm the device is in the target segment and campaign is active.