Start/Stop food detection

Add a function to setup the camera preview layer:

func setupPreviewLayer() {
    guard videoLayer == nil else { return }
    if let videoLayer = passioSDK.getPreviewLayer() {
        self.videoLayer = videoLayer
        videoLayer.frame = view.bounds
        DispatchQueue.main.async { [weak self] in
            self?.view.layer.insertSublayer(videoLayer, at: 0)
        }
    }
}

Add the method startFoodDetection() This code will throw a missing delegate conformance error that we will resolve in the next step, ignore it for now.

func startFoodDetection() {
    setupPreviewLayer()
    DispatchQueue.global(qos: .userInitiated).async { [weak self] in
        guard let self else { return }
        
        let config = FoodDetectionConfiguration(detectVisual: true,
                                                volumeDetectionMode: .none,
                                                detectBarcodes: true,
                                                detectPackagedFood: true)
        passioSDK.startFoodDetection(detectionConfig: config,
                                     foodRecognitionDelegate: self) { ready in
                print("SDK was not configured correctly")
        }
    }
}

Add a function to request authorization to use the camera and start recognition. Call the function from viewWillAppear:

Create a function to stop Food Detection and call it from viewWillDisappear:

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

Last updated