Docs / iOS / Quick start

iOS quick start

Add the Facevity pod with its MediaPipe subspec (or the Swift package), set up a licence and process CVPixelBuffer camera frames on Metal.

Demo app: facevity-ios-demo on GitHub

Facevity for iOS is a Swift SDK (Objective-C compatible) for iOS 15 and later. It runs the same beauty pipeline as Android on Metal, with the same parameters, presets, lipstick shades, filters, accessories and licences. Face landmarks come from MediaPipe Tasks Vision.

1. Install

# Podfile
platform :ios, '15.0'
use_frameworks!

target 'MyApp' do
  pod 'Facevity', :git => '<Facevity repository URL from your trial>', :tag => 'ios-v0.4.0'   # Core + MediaPipe
  # pod 'Facevity/Core', ...   engine only, bring your own FVDetectorProvider
end

The default pod includes two subspecs:

Subspec Contents
Facevity/Core The engine, licensing, props and the resource bundle FacevityResources (Metal shaders, models, canonical mesh, the prop pack). No third-party dependency.
Facevity/MediaPipe FVMediaPipeProvider: MediaPipe Face Landmarker and Image Segmenter. Pulls MediaPipeTasksVision (0.10.21 or later) and registers itself automatically.

The resource bundle carries both MediaPipe models (face landmarker 3.8 MB, segmentation 8.3 MB). The pod builds its Swift with -O also in Debug apps, because the tracker runs on the CPU every frame.

Swift Package Manager

// Package.swift
dependencies: [
    .package(url: "<Facevity package URL from your trial>", exact: "0.4.0")   // product "Facevity"
]

The Swift package is a binary Facevity.xcframework (device and Simulator). Google distributes MediaPipe Tasks for iOS through CocoaPods only, so a Swift package cannot depend on it. With SPM, either add pod 'MediaPipeTasksVision' and the one-file adapter FVMediaPipeProvider.swift (shipped with the SDK) to your app, or pass your own landmark provider in FacevityOptions.detectorProvider. CocoaPods is the simpler path.

Info.plist

Add NSCameraUsageDescription as for any camera app. The SDK itself needs no permission; online licence activation uses the network.

2. Create the engine and choose a look

import Facevity

let fv = try Facevity.initialize()          // loads the landmarker in the background
fv.setParams(.NATURAL)                       // or .DEFAULT, .GLAM, .NONE
fv.setSmoothIntensity(55)                    // 0 off, 50 natural, 100 strong
fv.setLipstick(BeautyColors.lipRed, level: 60)
fv.setProp("aviator")                        // AR props: fv.availableProps()

Change a few levels of a preset with with:

fv.setParams(BeautyParams.GLAM.with { $0.smooth(70).filter("warm", level: 40) })

Every 0..100 level follows one scale: 0 = off, 50 = natural, 100 = strong but still realistic (skinTone is -100..100). Setters, stats(), capabilities() and the licence calls work from any thread and take effect on the next frame.

3. Set up the licence

The licence is bound to your app’s bundle identifier. Pick one of three ways (details in Licensing):

let o = FacevityOptions()
o.licenseToken = token                          // A. a token from your backend (or later: fv.setLicenseToken(token))
o.licenseServerUrl = "https://<licence server from your trial>"
let fv = try Facevity.initialize(o)

fv.activateLicense("FV-XXXX-XXXX-XXXX-XXXX") { info in   // B. online activation, once per install
    print("Facevity licence:", info.status.name)
}

// C. an offline licence file
fv.setLicenseFile(url: Bundle.main.url(forResource: "facevity", withExtension: "fvl")!)

A file named facevity-license.fvl in the main bundle is loaded automatically at start when nothing else is installed. Without a valid licence the SDK keeps working with a “Facevity · unlicensed” watermark (or passes frames through with .passthrough).

4. Process camera frames

The main entry point processes a CVPixelBuffer in place (32BGRA, or NV12 420f / 420v):

extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
    func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer,
                       from connection: AVCaptureConnection) {
        guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
        let ts = Int64(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * 1e9)
        let rotation = FacevityFrames.portraitSensorRotation(frontCamera: isFront)   // 90 back, 270 front
        _ = fv.processPixelBuffer(pixelBuffer, rotation: rotation, timestampNs: ts)
        // hand the (processed) buffer to your preview, encoder or RTC SDK as before
    }
}

Other inputs:

fv.processPixelBuffer(input, into: output, rotation: 0, timestampNs: ts)       // into another buffer
let out = fv.processTexture(texture, rotation: 0, commandBuffer: nil)           // Metal: engine-owned RGBA8
fv.processBuffer(&bytes, format: .i420, width: w, height: h, rotation: 0, timestampNs: ts)   // NV21 / NV12 / I420
  • Rotation (0, 90, 180, 270) is how far the raw frame must turn clockwise to be upright. It is used only to find faces; the output keeps the input orientation. For buffers the capture connection does not rotate, use FacevityFrames.portraitSensorRotation(frontCamera:); for rotated buffers pass 0. RTC SDKs report it per frame.
  • Nothing throws on the frame path. A failure returns the input untouched and shows in stats().lastError.
  • Metal. With a command buffer, processTexture encodes its GPU work into your buffer after one CPU sync point; the returned texture stays valid until the call after next.
  • Frames are processed one at a time. A frame that arrives while another is in flight waits up to the frame budget, then passes through untouched, so the camera is never blocked.

5. Makeup, accessories and capabilities

fv.setLipstick(BeautyColors.lipRose, level: 60)       // licence feature beauty.makeup
fv.setTeethWhitening(50)                               // acts only while teeth show
fv.setBacklightFix(50)                                 // automatic, 0 = off

let props = fv.availableProps()                        // 9 built-in props: id, name, anchor
fv.setProp("flower_headband")                          // licence feature ar.props
fv.clearProp()

let caps = fv.capabilities()                           // hide controls the licence does not cover
fv.addCapabilitiesListener { caps in DispatchQueue.main.async { self.update(caps) } }

The lipstick region comes from the current frame’s lip contours, so the tint stays on the lips while the user speaks.

6. Tracking and lifecycle

  • trackingMode: .sync waits briefly for the landmarker’s result for the current frame (no frame of latency), .tracked and .trackedRigid use optical flow between results.
  • resetTracking() after a camera switch; facesDetected; setBeautyEnabled(false) for exact pass-through.
  • release() when the camera session ends.
  • stats() returns frame counters and timings; setDebugMaskView(0...7) shows the masks.

7. FaceUnity-style kit

FVRenderManager.setup(licenseToken:callback:options:) and FVRenderKit.shared (aiKit.loadAIProcessor(), faceBeauty = FVFaceBeauty(), renderWithInput(FVRenderInputData)) follow FaceUnity’s call flow with texture, CVPixelBuffer or byte-buffer input. See Migrating from FaceUnity.

Demo app and next steps

The iOS demo app shows camera beauty, licence handling and the call hooks.

Video calls: Agora, ZEGOCLOUD, LiveKit, WebRTC.

Need help with an integration? Contact the Facevity team. We answer integration questions during trials.