@ihealth/ihealthlibrary-react-native
Version:
React Native Model for iHealth Library
140 lines (101 loc) • 3.81 kB
Markdown
```shell
npm install --save @ihealth/ihealthlibrary-react-native
```
```shell
yarn add @ihealth/ihealthlibrary-react-native
```
1. Sign up iHealth developer webside. [Please sign up here](https://dev.ihealthlabs.com)
2. Press "Add New App" button, fill in your information of your app. We will get email and active the license for your app.
3. Download license file, as shown below.

For iOS
As shown below, Add your license file to your iOS project.

For Android
As show below, Add your license file to your asserts folder.

```js
import { iHealthDeviceManagerModule } from '@ihealth/ihealthlibrary-react-native';
// your license file
const filename = 'license.pem';
iHealthDeviceManagerModule.sdkAuthWithLicense(filename);
```
1. Check settings.gradle file in your android project and node_modules, make sure input the correct module path.
```gradle
include ':ihealthlibrary-react-native'
project(':ihealthlibrary-react-native').projectDir = new File(rootProject.projectDir,'../node_modules/@ihealth/ihealthlibrary-react-native/android')
```
2. Check build.gradle file in your android project, make sure the ihealth module is integrated
```gradle
compile project(':@ihealth_ihealthlibrary-react-native')
```
3. Import iHealth module in your MainActivity.java
```java
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new iHealthDeviceManagerPackage()
);
}
```
4. Location permission(in AndroidManifest.xml)
```xml
<!-- Need ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission in Android API 23+ -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
```
1. Open your iOS project, add node_modules/@ihealth/ihealthlibrary-react-native/ios/ReactNativeIOSLibrary.xcodeproj to libraries
2. Under 'Build Phases' -- 'Link Binary With Libraries', add libReactNativeIOSLibrary.a
iHealth SDK module is based on DeviceEventEmitter, So call add listener while the component is loaded, and call remove listener while the component is unloaded, As show as below. If you want more detail information, Please the example code.
```js
componentDidMount() {
iHealthAPI.addListener();
}
componentWillUnmount() {
iHealthAPI.removeListener();
}
```
```js
import { iHealthDeviceManagerModule } from '@ihealth/ihealthlibrary-react-native';
const type = 'BP5'; // AM3S, AM4, BG5, BG5S, BP3L, BP5, BP5S, BP7S, HS2, HS4S, PO3,HS2S,BG1S
iHealthDeviceManagerModule.startDiscovery(type);
```
```js
import { iHealthDeviceManagerModule } from '@ihealth/ihealthlibrary-react-native';
const mac = 'xxxxxxxxxxxxxx';
const type = 'BP5'; // AM3S, AM4, BG5, BG5S, BP3L, BP5, BP5S, BP7S, HS2, HS4S, PO3,HS2S,BG1S
iHealthDeviceManagerModule.connectDevice(mac, type);
```
[](./doc/am3s.md)
[](./doc/am4.md)
[](./doc/am5.md)
[](./doc/bg1.md)
[](./doc/bg5.md)
[](./doc/bg5s.md)
[](./doc/bp3l.md)
[](./doc/bp5.md)
[](./doc/bp5s.md)
[](./doc/bp7s.md)
[](./doc/hs2.md)
[](./doc/hs4s.md)
[](./doc/hs6.md)
[](./doc/po3.md)
[](./doc/hs2s.md)
[](./doc/bg1s.md)