quarvis-device-sdk-react-native
v1.0.12
Published
Quarvis Health device SDK for React Native
Readme
quarvis-device-sdk-react-native
Quarvis Health device SDK for React Native
Installation
npm install quarvis-device-sdk-react-native
cd ios && pod installAdd the following to your ios/Your-App/Info.plist:
<plist version="1.0">
<dict>
<!-- ... rest of your properties-->
<dict>
<!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need location access to use Bluetooth for connecting to devices.</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>We use Bluetooth to connect to nearby devices for enhanced functionality.</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Bluetooth access is required to communicate with nearby devices.</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
</dict>
</plist>Add the following to your android/app/proguard-rules.pro:
-keep class com.crrepa.ble.** { *; }Add the following to your android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourapp">
<!-- ... -->
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Android 12 specific permissions -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
</manifest>Usage
You can check the usage of the SDK in the example folder.
import { isBluetoothEnabled } from 'quarvis-device-sdk-react-native';
// ...
const result = await isBluetoothEnabled();Background synchronization
If you need a background synchronization, you can use the following package. Please, follow installation instructions from the package documentation.
Check the background synchronization in the example folder.
const initBackgroundFetch = useCallback(async () => {
const onEvent = async (taskId: string) => {
console.log('[BackgroundFetch] Received task: ', taskId);
try {
onGetTodayActivity();
const [sleepInfo, heartRateInfo, bloodOxInfo, stressInfo] =
await Promise.allSettled([
onGetSleepInfo(),
onGetHeartRate(),
onGetBloodOx(),
onGetStressInfo(),
]);
console.log('[BackgroundFetch] Received sync data:', {
sleepInfo: 'value' in sleepInfo ? sleepInfo?.value : null,
heartRateInfo:
'value' in heartRateInfo ? heartRateInfo?.value : null,
bloodOxInfo: 'value' in bloodOxInfo ? bloodOxInfo?.value : null,
stressInfo: 'value' in stressInfo ? stressInfo?.value : null,
receivedSteps,
});
} catch (error) {
console.error('[BackgroundFetch] Error in background sync:', error);
} finally {
BackgroundFetch.finish(taskId);
}
};
const onTimeout = async (taskId: string) => {
console.warn('[BackgroundFetch] TIMEOUT task: ', taskId);
BackgroundFetch.finish(taskId);
};
const status = await BackgroundFetch.configure(
{
minimumFetchInterval: 15,
stopOnTerminate: true,
enableHeadless: false,
startOnBoot: false,
forceAlarmManager: false,
requiredNetworkType: BackgroundFetch.NETWORK_TYPE_ANY,
},
onEvent,
onTimeout
);
console.log('[BackgroundFetch] configure status: ', status);
}, [
onGetBloodOx,
onGetHeartRate,
onGetSleepInfo,
onGetStressInfo,
onGetTodayActivity,
receivedSteps,
]);
useEffect(() => {
initBackgroundFetch();
}, [initBackgroundFetch]);Jest integration
Using QuarvisDeviceSdkReactNative in Jest tests requires mocking the native modules. You can use the following steps to mock the SDK in
Jest tests.
With mocks directory
- In your project root directory, create
__mocks__/quarvis-device-sdk-react-nativedirectory. - Inside that folder, create
index.tsfile. - Inside that file, export
quarvis-device-sdk-react-native/jestmock.
export * from 'quarvis-device-sdk-react-native/jest';With Jest setup file
- In your Jest config (probably in package.json) add setup files location:
{
"jest": {
"setupFiles": [
"./path/to/jestSetupFile.js"
]
}
}- Inside your setup file, set up
quarvis-device-sdk-react-nativmocking:
jest.mock('quarvis-device-sdk-react-native', () =>
require('quarvis-device-sdk-react-native/jest')
);Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
