Skip to content

Snapchat/camera-kit-ios-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Camera Kit brings the power of Snap's AR platform to your websites and mobile apps on iOS and Android. It has never been easier to create and deliver scalable, multi-platform AR experiences to meet your customers, wherever they are.

distort hair_simulation try_on 3d_hand_tracking wrist_wear_try_on eye_wear_try_on true_size_object vfx landmarkers

Features

AR Capabilities

  • Face Effects
  • Body / Face / Hand Tracking
  • World Tracking
  • Background Segmentation
  • Location AR
  • and many more

iOS SDK

  • Integrate with AVCaptureSession, which allows to maintain full control over session configuration, management, and lifecycle
  • Fetch and display your lenses
  • Capture media
  • Leverage Reference UI modules to quickly build Camera Kit based experiences
  • Supports iOS 13.0+

Integration Steps

  1. Setup your Camera Kit application using Developer Portal
  2. Integrate Camera Kit SDK into your iOS application
  3. Create AR experiences using Lens Studio and manage them using My Lenses site

Modules

A core module that handles AR experiences:

  • SCSDKCameraKit

A set of open-sourced, reusable UI components and utilities for easier development of Camera Kit based experiences:

  • SCSDKCameraKitReferenceUI
  • SCSDKCameraKitReferenceSwiftUI

Modules required for testing your in-development lenses (see Push-to-Device):

  • SCSDKCameraKitBaseExtension
  • SCSDKCameraKitLoginKitAuth
  • SCSDKCameraKitPushToDeviceExtension

Installation

  1. In Xcode, select "File" → "Add Package Dependencies…"
  2. Enter the repository URL: https://github.com/Snapchat/camera-kit-ios-sdk.git
  3. Select the version and modules you want to use in your project

If you use CocoaPods to manage your dependencies, simply add the following to your Podfile:

pod 'SCCameraKit'

If you'd like to use the Reference UI:

pod 'SCCameraKitReferenceUI'
pod 'SCCameraKitReferenceSwiftUI'

Manual

  1. Download the binaries from the Releases section
  2. Unzip and add the Camera Kit SDK .xcframework to your Xcode project
  3. In your target's "General" settings, add the framework to the "Frameworks, Libraries, and Embedded Content" section

Usage

You can find a more detailed tutorial here

Initializing Camera Kit

Obtain an API token for your Camera Kit application on Developer Portal

import SCSDKCameraKit

let sessionConfig = SessionConfig(apiToken: "<YOUR_API_TOKEN>")
let lensesConfig = LensesConfig(cacheConfig: CacheConfig(lensContentMaxSize: 150*1024*1024))
        
let cameraKit = Session(sessionConfig: sessionConfig, lensesConfig: lensesConfig, errorHandler: self)

Implementing Camera View

// Configure the camera preview view
let previewView = PreviewView()
previewView.automaticallyConfiguresTouchHandler = true
cameraKit.add(output: previewView)

// Configure the capture session
let captureSession = AVCaptureSession()
let input = AVSessionInput(session: captureSession)
let arInput = ARSessionInput()        
cameraKit.start(input: input, arInput: arInput)

DispatchQueue.global(qos: .background).async {
    input.startRunning()
}

Applying AR Lens

You can find lens group IDs and specific lens IDs on My Lenses site

// Observe a particular lens
cameraKit.lenses.repository.addObserver(self, specificLensID: "<LENS_ID>", inGroupID: "<LENS_GROUP_ID>")

// Implement LensRepositorySpecificObserver to receive observed Lens object
extension MyViewController: LensRepositorySpecificObserver {
    func repository(_ repository: LensRepository, didUpdate lens: Lens, forGroupID groupID: String) {
        lensQueue.async { [weak self] in
            guard let self = self else { return }

            // Apply a lens, which makes it visible on previewView
            self.cameraKit.lenses.processor?.apply(lens: lens, launchData: nil) { success in
                if success {
                    print("\(lens.name ?? "Unnamed") (\(lens.id)) Applied")
                } else {
                    print("Lens failed to apply")
                }
            }
        }
    }
    
    func repository(_ repository: LensRepository, didFailToUpdateLensID lensID: String, forGroupID groupID: String, error: Error?) {
        // Handle errors
    }
}

Samples

We provide several sample apps that demonstrate different approaches to integrating the Camera Kit SDK:

License

Camera Kit for iOS is available under a custom license. See the LICENSE file for more info.

Contributing

We welcome contributions to the open-sourced parts of Camera Kit for iOS - Reference UI and Sample Apps. Feel free to open issues and submit PRs.

Changelog

See CHANGELOG.md for details on each release.