Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Once the SDK is ready, you can start food detection.
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 {
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%'}} />
const config: FoodDetectionConfig = {
/**
* Detect barcodes on packaged food products. Results will be returned
* as `BarcodeCandidates` in the `FoodCandidates` property of `FoodDetectionEvent`
*/
detectBarcodes: true,
/**
* Results will be returned as DetectedCandidate in the `FoodCandidates`and
* property of `FoodDetectionEvent`
*/
detectPackagedFood: true,
};
useEffect(() => {
if (!isReady) {
return;
}
const subscription = PassioSDK.startFoodDetection(
config,
async (detection: FoodDetectionEvent) => {
const { candidates } = detection
if (candidates?.barcodeCandidates?.length) {
// show barcode candidates to the user
} else if (candidates?.packagedFoodCode?.length) {
// show OCR candidates to the user
} else if (candidates?.detectedCandidates?.length) {
// show visually recognized candidates to the user
}
},
);
// stop food detection when component unmounts
return () => subscription.remove();
}, [isReady]);
Try to run the above code in component and Point the phone to the image below and see if you are getting the correct food in console log Got food detection event
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
When starting food detection with PassioSDK.startFoodDetection
you will receive a FoodDetectionEvent
. This is the structure of that data class:
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com
It's return []
export interface FoodDetectionEvent {
/**
* A collection of food candidates detected by the models.
*/
candidates?: FoodCandidates;
}
/**
* A collection of food candidates detected by the models.
*/
export interface FoodCandidates {
/**
* Food candidate results from visual scanning. The array is sorted by confidence, with the most confident result at index 0.
*/
detectedCandidates: DetectedCandidate[]
/**
* Food candidate results from barcode scanning.
*/
barcodeCandidates?: BarcodeCandidate[]
/**
* Food candidate results from packagedFoodCode scanning.
*/
packagedFoodCode?: PackagedFoodCode[]
}
import {
PassioSDK,
type PassioSpeechRecognitionModel,
type PassioFoodDataInfo,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* @param text - Provide `text` to get `PassioSpeechRecognitionModel` list detail.
* @returns A `Promise` resolving to `PassioSpeechRecognitionModel` list.
*/
recognizeSpeechRemote(
text: string
): Promise<PassioSpeechRecognitionModel[] | null>
const recognizeSpeech = useCallback(
async (text: string) => {
try {
// Fetch food results from the PassioSDK based on the query
const recognizedModel = await PassioSDK.recognizeSpeechRemote(text)
setPassioSpeechRecognitionModel(recognizedModel)
} catch (error) {
// Handle errors, e.g., network issues or API failures
} finally {
// Reset loading state to indicate the end of the search
}
},
[cleanSearch]
)
import {
PassioSDK,
type PassioAdvisorFoodInfo,
type PassioFoodDataInfo,
} from '@passiolife/nutritionai-react-native-sdk-v3'
import { launchImageLibrary } from 'react-native-image-picker'
/**
* Retrieving food info using image uri,
* Smaller resolutions will result in faster response times
* while higher resolutions should provide more accurate results
* @param imageUri - The local URI of the image.
* @param message - An optional message to indicate the context of the image.
* @param resolution - enables the caller to set the target resolution of the image uploaded to the server, Default is RES_512
* @returns A `Promise` resolving to an array of `PassioAdvisorFoodInfo`.
*/
recognizeImageRemote(
imageUri: string,
message?: string,
resolution?: PassioImageResolution
): Promise<PassioAdvisorFoodInfo[] | null>
const onScanImage = useCallback(async () => {
try {
const { assets } = await launchImageLibrary({ mediaType: 'photo' })
if (assets) {
setLoading(true)
setPassioSpeechRecognitionModel(null)
PassioSDK.recognizeImageRemote(
assets?.[0].uri?.replace('file://', '') ?? ''
)
.then(async (candidates) => {
setPassioSpeechRecognitionModel(candidates)
})
.catch(() => {
Alert.alert('Unable to recognized this image')
})
.finally(() => {
setLoading(false)
})
}
} catch (err) {
setLoading(false)
}
}, [])
import {
PassioSDK,
type PassioFoodItem,
type PackagedFoodCode,
type PassioSearchResult,
type FoodSearchResult,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* Configure the SDK with the given options.
*
* @param options - The configuration options
* @returns A `Promise` resolving with a `PassioStatus` indicating the current state of the SDK.
*/
configure(options: ConfigurationOptions): Promise<PassioStatus>
/**
* Prompt the user for camera authorization if not already granted.
* @remarks Your app's Info.plist must inclue an `NSCameraUsageDescription` value or this method will crash.
* @returns A `Promise` resolving to `true` if authorization has been granted or `false` if not.
*/
requestCameraAuthorization(): Promise<boolean>
const [isReady, setIsReady] = useState(false);
const [isCameraAuthorized, setCameraAuthorized] = useState(false);
// Effect to configure the SDK and request camera permission
useEffect(() => {
const callBack = PassioSDK.configure(
{
key: "your passio license key",
debugMode: debugMode,
autoUpdate: autoUpdate,
},
(status: PassioStatus) => {
switch (status.mode) {
case 'notReady':
return
case 'isBeingConfigured':
return
case 'isDownloadingModels':
return
case 'isReadyForDetection':
setIsReady(true)
return
case 'error':
setIsReady(false)
return
}
}
)
return () => callBack.remove()
}, [key, debugMode, autoUpdate])
useEffect(() => {
PassioSDK.requestCameraAuthorization().then((cameraAuthorized) => {
setCameraAuthorized(cameraAuthorized);
});
}, []);
import {
PassioSDK,
type PassioFoodItem,
type PassioID,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* Look up the nutrition attributes for a given Passio ID.
* @param passioID - The Passio ID for the attributes query.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemForPassioID(passioID: PassioID): Promise<PassioFoodItem | null>
const getFoodItem = async (passioID: PassioID) => {
try {
const passioFoodItem = await PassioSDK.fetchFoodItemForPassioID(passioID)
} catch (error) {
console.log('error', error)
}
}
Once the SDK is ready, you can start nutrition label detection.
Android Platform: You need the user's permission to access the camera.
IOS Platform: Enter a value for NSCameraUsageDescription
in your Info.plist so the camera may be utilized.
To show the live camera preview, add the DetectionCameraView
to your view
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
get nutrients value using PassioFoodItemNutrients
To retrieve all macro and micronutrient values using fetchNutrientsForPassioFoodItem
, by passing a passioFoodItem
, you would typically follow these steps:
You will receive PassioNutrients
Search the database of foods with a given search term.
searchForFood
now returns PassioSearchResult and a list of search options. The PassioSearchResult represent a specific food item associated with the search term, while search options provide a list of possible suggested search terms connected to the input term.
You can utilize the searchForFood
API from the SDK to retrieve food records based on a search string. This API returns a PassioSearchResult
object containing both results
and alternatives
.
The results property holds an array of food search results, while the alternatives property provides additional suggestions or alternative options if available.
How to get PassioFoodItem
using SerchFood Response?
PassioSDK provide support to below api's
<uses-permission android:name="android.permission.CAMERA">
import {
PassioSDK,
DetectionCameraView,
} from '@passiolife/nutritionai-react-native-sdk-v3';
<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]);
/**
* fetch a map of nutrients for passio Food Item with calculated weight
* @param passioFoodItem - The passioFoodItem for the attributes query.
* @param weight - The weight for the query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsForPassioFoodItem(
passioFoodItem: PassioFoodItem,
weight: UnitMass
): PassioNutrients
/**
* fetch a map of nutrients for passio Food Item with default selected size
* @param passioFoodItem - The passioFoodItem for the attributes query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsSelectedSizeForPassioFoodItem(
passioFoodItem: PassioFoodItem
): PassioNutrients
/**
* fetch a map of nutrients for passio Food Item with reference weight Unit("gram",100)
* @param passioFoodItem - The passioFoodItem for the attributes query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsReferenceForPassioFoodItem(
passioFoodItem: PassioFoodItem
): PassioNutrients
PassioSDK.fetchNutrientsForPassioFoodItem(passioFoodItem,weight)
PassioSDK.fetchNutrientsSelectedSizeForPassioFoodItemFoodItem(passioFoodItem)
PassioSDK.fetchNutrientsReferenceForPassioFoodItem(passioFoodItem)
interface PassioNutrients {
weight?: UnitMass
vitaminA?: UnitMass
alcohol?: UnitMass
calcium?: UnitMass
calories?: UnitMass
carbs?: UnitMass
cholesterol?: UnitMass
fat?: UnitMass
fibers?: UnitMass
iodine?: UnitMass
iron?: UnitMass
magnesium?: UnitMass
monounsaturatedFat?: UnitMass
phosphorus?: UnitMass
polyunsaturatedFat?: UnitMass
potassium?: UnitMass
protein?: UnitMass
satFat?: UnitMass
sodium?: UnitMass
sugarAlcohol?: UnitMass
sugars?: UnitMass
sugarsAdded?: UnitMass
transFat?: UnitMass
vitaminB12?: UnitMass
vitaminB12Added?: UnitMass
vitaminB6?: UnitMass
vitaminC?: UnitMass
vitaminD?: UnitMass
vitaminE?: UnitMass
vitaminEAdded?: UnitMass
}
import {
PassioSDK,
type FoodSearchResult,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* Search the database of foods with a given search term.
* @param searchQuery - The search term to match against food item names.
* @returns A `Promise` resolving to an array of food item names.
*/
searchForFood(searchQuery: string): Promise<PassioSearchResult | null>
/**
* Detail of search food with a given search result.
* @param result - Provide `PassioSearchResult` object get `PassioFoodItem` detail.
* @returns A `Promise` resolving to `PassioFoodItem` detail.
*/
fetchSearchResult(result: FoodSearchResult): Promise<PassioFoodItem | null>
try {
// Fetch food results from the PassioSDK based on the query
const searchFoods = await PassioSDK.searchForFood(query)
} catch (error) {
// Handle errors, e.g., network issues or API failures
}
try {
// Fetch food results from the PassioSDK based on the query
const passioFoodItem = await PassioSDK.fetchSearchResult(foodSearchResult)
} catch (error) {
// Handle errors, e.g., network issues or API failures
}
import {
PassioSDK,
type Callback,
type DownloadingError,
type CompletedDownloadingFile
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* This method indicating downloading file status if model download from passio server.
* @param callback - A callback to receive for dowloading file lefts from queue.
* @param callback - A callback to receive dowload file failed for some reason.
* @returns A `Callback` that should be retained by the caller while dowloading is running. Call `remove` on the callback to terminate listeners and relase from memory.
*/
onDowloadingPassioModelCallBacks: (
downloadModelCallBack: DownloadModelCallBack
) => Callback
const [leftFile, setDownloadingLeft] = useState<number | null>(null)
useEffect(() => {
const callBacks = PassioSDK.onDowloadingPassioModelCallBacks({
completedDownloadingFile: ({ filesLeft }: CompletedDownloadingFile) => {
setDownloadingLeft(filesLeft)
},
downloadingError: ({ message }: DownloadingError) => {
console.log('DownloadingError ===>', message)
},
})
return () => callBacks.remove()
}, [])
/**
* Configure the SDK with the given options.
*
* @param options - The configuration options
* @returns A `Promise` resolving with a `PassioStatus` indicating the current state of the SDK.
*/
configure(options: ConfigurationOptions): Promise<PassioStatus>
/**
* Prompt the user for camera authorization if not already granted.
* @remarks Your app's Info.plist must inclue an `NSCameraUsageDescription` value or this method will crash.
* @returns A `Promise` resolving to `true` if authorization has been granted or `false` if not.
*/
requestCameraAuthorization(): Promise<boolean>
/**
* This method indicating downloading file status if model download from passio server.
* @param callback - A callback to receive for dowloading file lefts from queue.
* @param callback - A callback to receive dowload file failed for some reason.
* @returns A `Callback` that should be retained by the caller while dowloading is running. Call `remove` on the callback to terminate listeners and relase from memory.
*/
onDowloadingPassioModelCallBacks: (
downloadModelCallBack: DownloadModelCallBack
) => Callback
/**
* Begin food detection using the device's camera.
* @param options - An object to determine which types of scanning should be performed.
* @param callback - A callback to repeatedly receive food detection events as they occur.
* @returns A `Subscription` that should be retained by the caller while food detection is running. Call `remove` on the subscription to terminate food detection.
*/
startFoodDetection(
options: FoodDetectionConfig,
callback: (detection: FoodDetectionEvent) => void
): Subscription
/**
* Begin nutrition fact label detection using the device's camera.
* @param callback - A callback to repeatedly receive nutrition detection events as they occur.
* @returns A `Subscription` that should be retained by the caller while nutrition detection is running. Call `remove` on the subscription to terminate nutrition detection.
*/
startNutritionFactsDetection(
callback: (detection: NutritionDetectionEvent) => void
): Subscription
/**
* Look up the food item result for a given Passio ID.
* @param passioID - The Passio ID for the query.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemForPassioID(passioID: PassioID): Promise<PassioFoodItem | null>
/**
* Look up the food item result for a given by barcode or packagedFoodCode.
* @param barcode - barcode for the query.
* or
* @param packageFoodCode - packageFoodCode for the query.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemForProductCode(
code: Barcode | PackagedFoodCode
): Promise<PassioFoodItem | null>
/**
* Search the database of foods with a given search term.
* @param searchQuery - The search term to match against food item names.
* @returns A `Promise` resolving to an array of food item names.
*/
searchForFood(searchQuery: string): Promise<PassioSearchResult | null>
/**
* Search for food semantic will return a list of alternate search and search result
* @param searchQuery - User typed text.
* @returns A `Promise` resolving to an array of food item result.
*/
searchForFoodSemantic(searchQuery: string): Promise<PassioSearchResult | null>
/**
* gives a list of predicted next ingredients based on the current list of ingredients in the recipe
* @param currentIngredients - List of food ingredients name.
* @returns A `Promise` resolving to an array of food data info.
*/
predictNextIngredients(
currentIngredients: string[]
): Promise<PassioFoodDataInfo[] | null>
/**
* Data info of the food with a given result.
* @param passioFoodDataInfo - Provide `PassioFoodDataInfo` object get `PassioFoodItem` detail.
* @param servingQuantity - Provide `servingQuantity` number to get `PassioFoodItem` detail.
* @param servingUnit - Provide `servingUnit` unit to get `PassioFoodItem` detail.
* @returns A `Promise` resolving to `PassioFoodItem` detail.
*/
fetchFoodItemForDataInfo(
passioFoodDataInfo: PassioFoodDataInfo,
servingQuantity?: number,
servingUnit?: String
): Promise<PassioFoodItem | null>
/**
* Retrieving food info using image uri,
* Smaller resolutions will result in faster response times
* while higher resolutions should provide more accurate results
* @param imageUri - The local URI of the image.
* @param message - An optional message to indicate the context of the image.
* @param resolution - enables the caller to set the target resolution of the image uploaded to the server, Default is RES_512
* @returns A `Promise` resolving to an array of `PassioAdvisorFoodInfo`.
*/
recognizeImageRemote(
imageUri: string,
message?: string,
resolution?: PassioImageResolution
): Promise<PassioAdvisorFoodInfo[] | null>
/**
* Retrieving nutrition facts using image uri,
* Smaller resolutions will result in faster response times
* while higher resolutions should provide more accurate results
* @param imageUri - The local URI of the image.
* @param resolution - enables the caller to set the target resolution of the image uploaded to the server, Default is RES_512
* @returns A `Promise` resolving to an array of `PassioFoodItem`.
*/
recognizeNutritionFactsRemote(
imageUri: string,
resolution?: PassioImageResolution
): Promise<PassioFoodItem | null>
/**
* @param text - Provide `text` to get `PassioSpeechRecognitionModel` list detail.
* @returns A `Promise` resolving to `PassioSpeechRecognitionModel` list.
*/
recognizeSpeechRemote(
text: string
): Promise<PassioSpeechRecognitionModel[] | null>
/**
* This method adds personalized alternative to local database.
* Status: This method is experimental and only available in the iOS SDK.
* @param personalizedAlternative - The personalized alternative to add.
* @returns A `boolean` value indicating if the personalized alternative was added successfully.
*/
addToPersonalization(
visualCandidate: DetectedCandidate,
alternative: DetectedCandidate
): boolean
/**
* This method fetches tags for a given Passio ID.
* @param passioID - The Passio ID for the tags query.
* @returns A `string` array of tags if the record exists in the database or `null` if not.
*/
fetchTagsForPassioID(passioID: PassioID): Promise<string[]>
/**
* Look up the food item result for a given refCode.
* @param refCode - The refCode for the query.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemForRefCode(refCode: RefCode): Promise<PassioFoodItem | null>
/**
* fetch a map of nutrients for a 100 grams of a specific food item
* @param passioID - The Passio ID for the attributes query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsFor(passioID: PassioID): Promise<PassioNutrient[] | null>
/**
* fetch a suggestions for particular meal time 'breakfast' | 'lunch' | 'dinner' | 'snack' and returning results.
* @param mealTime - 'breakfast' | 'lunch' | 'dinner' | 'snack',
* @returns A `Promise` resolving to a `PassioFoodDataInfo` object if the record exists in the database or `null` if not.
*/
fetchSuggestions(
mealTime: PassioMealTime
): Promise<PassioFoodDataInfo[] | null>
/**
* fetch list of all meal Plans
* @returns A `Promise` resolving to a `PassioMealPlan` array if the record exists in the database or `null` if not.
*/
fetchMealPlans(): Promise<PassioMealPlan[] | null>
/**
* fetch list of all meal Plan item
* @param mealPlanLabel - query for type of mealPlan.
* @param day - for which day meal plan is needed
* @returns A `Promise` resolving to a `PassioMealPlanItem` array if the record exists in the database or `null` if not.
*/
fetchMealPlanForDay(
mealPlanLabel: string,
day: number
): Promise<PassioMealPlanItem[] | null>
/**
* fetch a map of nutrients for passio Food Item with calculated weight
* @param passioFoodItem - The passioFoodItem for the attributes query.
* @param weight - The weight for the query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsForPassioFoodItem(
passioFoodItem: PassioFoodItem,
weight: UnitMass
): PassioNutrients
/**
* fetch a map of nutrients for passio Food Item with default selected size
* @param passioFoodItem - The passioFoodItem for the attributes query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsSelectedSizeForPassioFoodItem(
passioFoodItem: PassioFoodItem
): PassioNutrients
/**
* fetch a map of nutrients for passio Food Item with reference weight Unit("gram",100)
* @param passioFoodItem - The passioFoodItem for the attributes query.
* @returns A `Promise` resolving to a `PassioNutrient` object if the record exists in the database or `null` if not.
*/
fetchNutrientsReferenceForPassioFoodItem(
passioFoodItem: PassioFoodItem
): PassioNutrients
/**
* @param passioID - passioID for the query.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemLegacy(passioID: PassioID): Promise<PassioFoodItem | null>
/**
* Added support for localized content.
* with a two digit ISO 639-1 language code will transform the food names and serving sizes in the SDK responses
*
* @param languageCode - with a two digit ISO 639-1 language code
*/
updateLanguage(languageCode: string): Promise<Boolean>
/**
* fetch list of possible hidden ingredients for a given food name.
* @param foodName - query for foodName.
* @returns A `Promise` resolving to a `PassioFetchAdvisorInfoResult`.
*/
fetchHiddenIngredients(
foodName: string
): Promise<PassioFetchAdvisorInfoResult>
/**
* fetch list of possible visual alternatives for a given food name.
* @param foodName - query for foodName.
* @returns A `Promise` resolving to a `PassioFetchAdvisorInfoResult`.
*/
fetchVisualAlternatives(
foodName: string
): Promise<PassioFetchAdvisorInfoResult>
/**
* fetch list of possible ingredients if a more complex food for a given food name.
* @param foodName - query for foodName.
* @returns A `Promise` resolving to a `PassioFetchAdvisorInfoResult`.
*/
fetchPossibleIngredients(
foodName: string
): Promise<PassioFetchAdvisorInfoResult>
Added support for localized content
Initialize Passio configuration at the entry point to enable localized content.
/**
* Added support for localized content.
* with a two digit ISO 639-1 language code will transform the food names and serving sizes in the SDK responses
*
* @param languageCode - with a two digit ISO 639-1 language code
*/
updateLanguage(languageCode: string): Promise<Boolean>
try {
// Fetch food results from the PassioSDK based on the query
const result = await PassioSDK.updateLanguage("fr")
console.warn(result)
} catch (error) {
}
The image uri to detect food.
import {
PassioSDK,
type FoodCandidates,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* This method detect food from image uri.
* @param imageUri - The image uri to detect food.
* @returns A `Promise` resolving to a `FoodCandidates` object if the record exists in the database or `null` if not.
*/
detectFoodFromImageURI(imageUri: string): Promise<FoodCandidates | null>
const [candidates, setCandidates] = useState<FoodCandidates | null>()
useEffect(() => {
PassioSDK.detectFoodFromImageURI(imageUri).then((foodCandidates) => {
setCandidates(foodCandidates)
})
}, [props.imageUri])
import {
PassioSDK,
type PassioFoodItem,
type PackagedFoodCode,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* Query Passio's web service for nutrition attributes given an package food identifier.
* @param packagedFoodCode - The code identifier for the attributes query, taken from the list of package food candidates on a `FoodDetectionEvent`.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemForProductCode(
code: Barcode | PackagedFoodCode
): Promise<PassioFoodItem | null>
Its' return PassioFoodItem
const getFoodItem = async (code: Barcode | PackagedFoodCodeackagedFoodCode) => {
try {
const passioFoodItem = await PassioSDK.fetchFoodItemForProductCode(code)
} catch (error) {
console.log('error', error)
}
}
fetch list of possible hidden ingredients for a given food name.
import {
RefCode,
type PassioFoodItem,
type PackagedFoodCode,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* Look up the food item result for a given refCode.
* @param refCode - The refCode for the query.
* @returns A `Promise` resolving to a `PassioFoodItem` object if the record exists in the database or `null` if not.
*/
fetchFoodItemForRefCode(
refCode: RefCode
): Promise<PassioFoodItem | null>
const getFoodItem = async (code: RefCode) => {
try {
const passioFoodItem = await PassioSDK.fetchFoodItemForRefCode(code)
} catch (error) {
console.log('error', error)
}
}
import {
PassioSDK,
type PersonalizedAlternative,
} from '@passiolife/nutritionai-react-native-sdk-v3'
/**
* This method adds personalized alternative to local database.
* Status: This method is experimental and only available in the iOS SDK.
* @param personalizedAlternative - The personalized alternative to add.
* @returns A `boolean` value indicating if the personalized alternative was added successfully.
*/
addToPersonalization(
personalizedAlternative: PersonalizedAlternative
): boolean
const personalizedAlternative = {
visualPassioID: "PassioID"
nutritionalPassioID: "PassioID"
servingUnit: "g"
servingSize: 10
}
const addToPersonalization = async (personalizedAlternative: PersonalizedAlternative) => {
try {
const isPersonalization = await PassioSDK.addToPersonalization(personalizedAlternative)
} catch (error) {
console.log('error', error)
}
}
/**
* fetch list of possible hidden ingredients for a given food name.
* @param foodName - query for foodName.
* @returns A `Promise` resolving to a `PassioFetchAdvisorInfoResult`.
*/
fetchHiddenIngredients(
foodName: string
): Promise<PassioFetchAdvisorInfoResult>
try {
// Fetch food results from the PassioSDK based on the query
const result = await PassioSDK.fetchHiddenIngredients("apple")
console.warn(result)
} catch (error) {
}
fetch list of possible visual alternatives for a given food name.
fetch list of possible ingredients if a more complex food for a given food name.
/**
* fetch list of possible visual alternatives for a given food name.
* @param foodName - query for foodName.
* @returns A `Promise` resolving to a `PassioFetchAdvisorInfoResult`.
*/
fetchVisualAlternatives(
foodName: string
): Promise<PassioFetchAdvisorInfoResult>
try {
// Fetch food results from the PassioSDK based on the query
const result = await PassioSDK.fetchVisualAlternatives("apple")
console.warn(result)
} catch (error) {
}
/**
* fetch list of possible ingredients if a more complex food for a given food name.
* @param foodName - query for foodName.
* @returns A `Promise` resolving to a `PassioFetchAdvisorInfoResult`.
*/
fetchPossibleIngredients(
foodName: string
): Promise<PassioFetchAdvisorInfoResult>
try {
// Fetch food results from the PassioSDK based on the query
const result = await PassioSDK.fetchPossibleIngredients("apple")
console.warn(result)
} catch (error) {
}