How to apply makeup effect in iOS App

Options
Mohammad Hussain
Mohammad Hussain Posts: 2
edited May 24 in General #1

import Foundation
import SwiftUI
import SCSDKCameraKit
import SCSDKCameraKitReferenceUI
import SCSDKCreativeKit

struct CameraKitCaptureSessionView: UIViewControllerRepresentable {

class Coordinator: NSObject {
    var parent: CameraKitCaptureSessionView

    init(_ parent: CameraKitCaptureSessionView) {
        self.parent = parent
    }
}

let snapAPI = SCSDKSnapAPI()

private enum Constants {
    static let partnerGroupId = "9ffe61e6-5533-4d04-9fb8-7efd0bd9438d"
}

var cameraController: CustomizedCameraController

private let debugStore: (any DebugStoreProtocol)? = {
    if #available(iOS 13, *) {
        return DebugStore(defaultGroupIDs: [SCCameraKitLensRepositoryBundledGroup, Constants.partnerGroupId])
    } else {
        return nil
    }
}()

fileprivate var supportedOrientations: UIInterfaceOrientationMask = .allButUpsideDown

init() {
    if let token = debugStore?.apiToken {
        cameraController = CustomizedCameraController(sessionConfig: SessionConfig(apiToken: token))
    } else {
        cameraController = CustomizedCameraController()
    }
    if let previousGroupIDs = debugStore?.groupIDs {
        cameraController.groupIDs = previousGroupIDs
    } else {
        cameraController.groupIDs = [SCCameraKitLensRepositoryBundledGroup, Constants.partnerGroupId]
    }
}
func makeUIViewController(context: Context) -> CustomizedCameraViewController {
    let cameraViewController = CustomizedCameraViewController(cameraController: cameraController, debugStore: debugStore)
    cameraViewController.appOrientationDelegate = context.coordinator
    return cameraViewController
}

func updateUIViewController(_ uiViewController: CustomizedCameraViewController, context: Context) {
    // Update the view controller if needed
}

func makeCoordinator() -> Coordinator {
    Coordinator(self)
}

func cameraKitViewController(_ viewController: UIViewController, openSnapchat screen: SnapchatScreen) {
    switch screen {
    case .profile, .lens(_):
        // not supported yet in creative kit (1.4.2), should be added in next version
        break
    case .photo(let image):
        let photo = SCSDKSnapPhoto(image: image)
        let content = SCSDKPhotoSnapContent(snapPhoto: photo)
        sendSnapContent(content, viewController: viewController)
    case .video(let url):
        let video = SCSDKSnapVideo(videoUrl: url)
        let content = SCSDKVideoSnapContent(snapVideo: video)
        sendSnapContent(content, viewController: viewController)
    }
}

private func sendSnapContent(_ content: SCSDKSnapContent, viewController: UIViewController) {
    viewController.view.isUserInteractionEnabled = false
    snapAPI.startSending(content) { error in
        DispatchQueue.main.async {
            viewController.view.isUserInteractionEnabled = true
        }
        if let error = error {
            print("Failed to send content to Snapchat with error: \(error.localizedDescription)")
            return
        }
    }
}

}

extension CameraKitCaptureSessionView.Coordinator: AppOrientationDelegate {
func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
parent.supportedOrientations = orientation
}

func unlockOrientation() {
    parent.supportedOrientations = .allButUpsideDown
}

}

**I have successfully added CameraKit into my iOS App using above code.But now I need to apply several makeup effects and also need video call filters how can i achieve this?

I have also requested for CameraKit access but doesn't get any response from Snap team.**

Tagged:

Answers

  • stevenxu
    stevenxu Posts: 611 👻
    Options

    Hi there. Thanks for posting on the forum. Please review our terms and policies to see if your use case is compliant for access to Camera Kit. Thanks!

This discussion has been closed.