Skip to main content
Camera Kit
iOS

Building a Camera Kit App for iOS Using Reference UI (SwiftUI)

In this tutorial, you'll learn how to build a fully-fledged Camera Kit application for iOS using Reference UI components in just a few lines of code.

Prerequisites

  • You have a Snapchat Developer Account and have created a Camera Kit application on the Developer Portal
  • Basic knowledge of Swift and SwiftUI
  • Latest Xcode installed
Section 1

Getting Started

Let's prepare our local development environment and add the Camera Kit SDK as a dependency using Swift Package Manager.

Step 1

Download the project files above and open Starting Project/CameraKitBasicReferenceSwiftUISample.xcodeproj

Step 2

Select "File" → "Add Package Dependencies…".

Paste the following link into the search box: https://github.com/Snapchat/camera-kit-ios-sdk.

Press "Add Package" to begin adding Camera Kit to your project.

Step 3

After Xcode finishes downloading the package, select SCSDKCameraKit, SCSDKCameraKitReferenceUI and SCSDKCameraKitReferenceSwiftUI.

Set everything else to "None" and press "Add Package".

We are now done adding Camera Kit as a dependency to your project.

Loading
Loading
Next Section
Building the App Using Reference UI Components
Section 2

Building the App Using Reference UI Components

We'll start by defining our credentials: API token and Lens group ID. Then, we'll create and configure a CameraController and finally present the CameraView.

Step 1

Open ContentView.swift and import SCSDKCameraKit library

This library provides access to core Camera Kit functionalities.

Step 2

Import SCSDKCameraKitReferenceUI

This library provides access to high-level UI components (UIKit based) and utilities that simplify building Camera Kit-based experiences.

Step 3

And finally import SCSDKCameraKitReferenceSwiftUI

This library wraps SCSDKCameraKitReferenceUI views so they can be used in SwiftUI

Step 4

Define your API token and Lens group ID

You can find them by navigating to My Lenses and selecting your application. You can use Staging API Token and Demo Lens Group ID for this tutorial

Step 5

Initialize CameraController with the API token

This object encapsulates the most common Camera Kit operations and provides a high-level API.

Step 6

Configure the CameraController with the Lens Group Id

Step 7

Declare CameraView and initialize it with CameraController

This view implements the camera preview, controls, and a carousel-like UI to navigate a set of lenses similar to the Snapchat experience.

Step 8

Go to your target settings, select "Info" tab and add Privacy items related to camera and microphone permissions.

Step 9

Run the app

You should now see a complete Camera Kit experience with camera controls and lenses carousel.

ContentView.swift
ContentView.swift
ContentView.swift
ContentView.swift
ContentView.swift
ContentView.swift
ContentView.swift
Summary
Finish & Review

Summary

You've now successfully built a Camera Kit-based app using the Reference UI for SwiftUI. While Reference UI allows you to get results and iterate quickly, it may not provide the flexibility you might desire compared to the lower-level API from Camera Kit.

Was this page helpful?
Yes
No