This documentation is intended to guide React Native developers through the process of integrating and utilizing the NutritionSDK in their projects. The NutritionSDK provides various methods to manage nutrition-related data and user preferences.
To integrate the NutritionSDK in your React Native project using Swift Package Manager, follow these steps:
-
Open your project in Xcode: First, ensure your React Native project is open in Xcode.
-
Adding Swift Package:
- Go to
File
->Swift Packages
->Add Package Dependency
. - Enter the URL for the NutritionSDK:
https://github.com/miguelmunozfer/NutritionSDKPlugin
- Follow the prompts to choose the version and options for integrating the package into your project.
- Go to
-
Verifying Integration:
- Once added, ensure that the NutritionSDK package appears in the Swift Package Dependencies section of your project.
- You can now use the SDK as per the documentation provided.
This process will integrate the NutritionSDK into your React Native project, allowing you to utilize its functionalities through Swift and bridging to React Native.
Before starting, ensure that your React Native project is set up and ready to integrate native modules.
- Place the
NutritionSDKBridge.swift
andNutritionSDKBridge.m
along with any other required Swift files in your project's directory.
- If you haven't already, create a bridging header to use Swift with Objective-C in your project. This is usually done automatically by Xcode when you add a new Swift file to an Objective-C project.
- Add
#import "React/RCTBridgeModule.h"
to the bridging header.
After successfully integrating the SDK, you can use the provided methods in your React Native JavaScript code. Here’s a brief overview of the available methods:
Starts the NutritionSDK session with the given user credentials.
user
: String - The user identifier.appID
: String - The application ID.password
: String - The password.
import { NutritionSDKBridge } from 'NativeModules';
NutritionSDKBridge.start('username', 'appId', 'password');
Updates the user's profile with the provided details.
sex
: String (optional) - The user's gender. The possible options are:Male
for maleFemale
for female
height
: Number (optional) - The user's height in centimeters.weight
: Number (optional) - The user's weight in kilograms.birthDateString
: String (optional) - The user's birth date in 'yyyy-MM-dd' format.
NutritionSDKBridge.updateProfile('Male', 180, 75, '1990-01-01');
Displays the nutrition module.
NutritionSDKBridge.showNutritionModule();
Checks if the user's profile is completely filled.
NutritionSDKBridge.isProfileFilled().then(isFilled => {
console.log('Is profile filled:', isFilled);
});
Sets the member ID for the user.
memberId
: String - The member identifier.
NutritionSDKBridge.setMemberId('memberId');
Sets the user's country in the SDK.
country
: Int - The country identifier, based on NutritionUserCountry enum. The possible options are:- Spain = 1
- Portugal = 2
- Colombia = 3
- UK = 4
- USA = 9
- Germany = 10
- Italy = 11
- Cataluña = 12
NutritionSDKBridge.setCountry(1); // For Spain
Starts a new session with the provided app ID and password.
appID
: String - The application ID.password
: String - The password.
NutritionSDKBridge.startSession('appID', 'password');
Logs out the current user from the SDK.
NutritionSDKBridge.logout();
Sets the main color theme for the SDK's UI elements.
color
: String - The color in a string format (e.g., hex code).
NutritionSDKBridge.setMainColor('FF5733'); // Example with a hex color code
Sets the navigation bar color.
color
: String - The color in a string format.
NutritionSDKBridge.setNavigationBarColor('007AFF');
Sets the navigation tint color, which is often used for button items in the navigation bar.
color
: String - The color in a string format.
NutritionSDKBridge.setNavigationTintColor('FFFFFF');
Sets the title for the navigation bar.
title
: String - The title text.
NutritionSDKBridge.setNavigationTitle('My Nutrition App');
Sets the language for the SDK.
language
: String - The language identifier. The possible options are:es
for Spanishen
for Englishpt
for Portuguesede
for Germanca
for Catalanit
for Italian
NutritionSDKBridge.setLanguage('en'); // For English
- Ensure that the data types passed from JavaScript match the expected types in Swift.
- Some functions might require additional handling based on the NutritionIASDK's requirements and capabilities.
This documentation provides a basic outline for using the NutritionSDK in a React Native environment. Developers may need to adjust usage and implementation details based on their specific project needs and the SDK's capabilities.