How do I integrate Amigo AI SDK into my iOS app?
The SDK provides three integration levels: drop-in SwiftUI/UIKit views, a per-frame API for custom pipelines, and static image swap. All run on-device via CoreML.
System Requirements
- iOS 16.0 or later
- Xcode 15.0 or later
- Swift 5.9 or later
- Device with A12 Bionic chip or later
Installation (Swift Package Manager)
In Xcode: File → Add Package Dependencies → enter:
https://github.com/AmigoAIAdmin/AmigoSDK_iOS.git
Step 1: Initialize ($0.01/session)
try await AmigoFaceSwap.initialize(apiKey: "your-api-key") { progress in
print("Downloading models: \(Int(progress * 100))%")
}
This validates your API key, downloads models if needed (the onProgress callback is invoked only on first run; models are then cached locally), and pre-warms the CoreML engine so the first frame has no cold-start delay. Each initialize call creates one billable session — call it once at app launch, not per request.
Step 2: Enroll a Face
Extract a reusable face embedding from a photo of the identity you want to wear on the live camera:
let latent = try await AmigoFaceSwap.enrollFace(from: sourcePhoto)
The returned FaceLatent is a 512-dimensional embedding. Cache it and reuse it — switch identities at runtime with zero latency. You can also construct from pre-computed server-side embeddings:
let latent = FaceLatent(embedding: myFloatArray) // [Float] with 512 elements
Live Camera — SwiftUI
import AmigoFaceSwapSDK
import SwiftUI
struct FaceSwapView: View {
let latent: FaceLatent
var body: some View {
AmigoLiveCameraView(targetLatent: latent)
.ignoresSafeArea()
}
}
To receive each processed frame (for recording or streaming):
AmigoLiveCameraView(targetLatent: latent) { frame in
myEncoder.encode(frame) // UIImage
}
Live Camera — UIKit
let vc = AmigoLiveViewController(targetLatent: latent)
present(vc, animated: true)
Advanced: AmigoLiveSession
For full control over the camera session:
let session = AmigoLiveSession(targetLatent: latent)
session.delegate = self
view.addSubview(session.previewView)
session.previewView.frame = view.bounds
session.start()
// Switch faces at runtime
session.targetLatent = newLatent
// Background replacement
session.backgroundImage = UIImage(named: "office")
// Toggle face swap on/off
session.isFaceSwapEnabled = false
Per-Frame API (WebRTC / Custom Pipelines)
For WebRTC, video playback, or any custom frame source:
// Call from a serial background queue (e.g., AVFoundation videoDataOutputQueue)
if let output = try AmigoFaceSwap.processFrame(pixelBuffer, using: latent) {
// render output (CIImage) to your display layer
}
// Returns nil when no face detected — render the original frame
Static Image Swap
let result = try await AmigoFaceSwap.swapFace(
in: targetPhoto,
using: latent,
lipMode: .innerLips
)
imageView.image = result
LipMode
Control lip blending behavior:
| Mode | Description |
|------|-------------|
| .none | Source face lips as-is |
| .outerLips | Blend outer lip region |
| .innerLips | Blend inner lip region (default, most natural) |
Cache Management
// Clear all cached models (forces re-download)
AmigoFaceSwap.clearModelCache()