Initialize and configure the SDK

At the top of your view controller import the PassioNutritionAISDK and AVFoundation

import AVFoundation
import PassioNutritionAISDK

Add the following properties to your view controller.

let passioSDK = PassioNutritionAI.shared
var videoLayer: AVCaptureVideoPreviewLayer?
var isSDKConfigured = false
var isProcessingResult = false

Create a function to configure the SDK and call it from viewDidLoad. Use the SDK key you received from Passio. We'll add the function for checkCameraAuthorizationAndStartDetection in the next step, so ignore the error for now.

func configureSDK() {
    let key = "Your_SDK_Key"
    let passioConfig = PassioConfiguration(key: key)
    passioSDK.configure(passioConfiguration: passioConfig) { [weak self] status in
        guard let self else { return }
        
        print("Mode = \(status.mode)\nmissingfiles = \(String(describing: status.missingFiles))" )
        self.isSDKConfigured = (status.mode == .isReadyForDetection)
        if self.isSDKConfigured {
            DispatchQueue.main.async {
                self.checkCameraAuthorizationAndStartDetection()
            }
        } else {
            print("SDK configuration failed. Mode: \(status.mode)")
        }
    }
}
override func viewDidLoad() {
    super.viewDidLoad()
    configureSDK()
}

You will receive the PassioStatus back from the SDK.

public struct PassioStatus {
    public internal(set) var mode: PassioSDK.PassioMode { get }
    public internal(set) var missingFiles: [PassioSDK.FileName]? { get }
    public internal(set) var debugMessage: String? { get }
    public internal(set) var activeModels: Int? { get }
}

public enum PassioMode {
    case notReady
    case isBeingConfigured
    case isDownloadingModels
    case isReadyForDetection
    case failedToConfigure
}

If at any point you need help from the Passio team, please reach out to us at support@passiolife.com

Last updated