startNutritionFactsDetection
Once the SDK is ready, you can start nutrition label detection.
Camera
Android Platform: You need the user's permission to access the camera.
<uses-permission android:name="android.permission.CAMERA">
IOS Platform: Enter a value for NSCameraUsageDescription
in your Info.plist so the camera may be utilized.
Import the SDK
import {
PassioSDK,
DetectionCameraView,
} from '@passiolife/nutritionai-react-native-sdk-v3';
To show the live camera preview, add the DetectionCameraView
to your view
<DetectionCameraView style={{flex: 1, width: '100%'}} />
useEffect(() => {
// Fistst check sdk configuration is ready for detection
if (!isReady) {
return;
}
const subscription = PassioSDK.startNutritionFactsDetection(
async (detection: NutritionDetectionEvent) => {
const { nutritionFacts: facts } = detection
if (facts !== undefined) {
setNutritionFacts(facts)
return
}
},
);
// stop food detection when component unmounts
return () => subscription.remove();
}, [isReady]);
Try to run the above code in the component and Point the phone to the image below and see if you are getting the correct nutrients lable in the console log
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
Last updated