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() {
// If you are using SDK key
let key = "Your_SDK_Key"
let passioConfig = PassioConfiguration(key: key)
// If you are using Proxy URL
var passioConfig = PassioConfiguration()
passioConfig.proxyUrl = "https://yourdomain.com/nutrition/"
passioConfig.proxyHeaders = ["header" : "value"] // Set required headers
passioSDK.configure(passioConfiguration: passioConfig) { [weak self] status in
guard let self else { return }
print("Mode = \(status.mode)\n missingfiles = \(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)")
}
}
}
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