configure & requestCameraAuthorization
Import
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>
Example
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);
});
}, []);
Last updated