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:
func checkCameraAuthorizationAndStartDetection() {
if AVCaptureDevice.authorizationStatus(for: .video) == .authorized {
startFoodDetection()
} else {
AVCaptureDevice.requestAccess(for: .video) { granted in
if granted {
DispatchQueue.main.async { [weak self] in
self?.startFoodDetection()
}
} else {
print("The user didn't grant access to use camera")
}
}
}
}