Skip to content

React Native 0.60+ linking with cocoapods and better documentation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Document/ReleaseNote.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Release Date: 2020-9-18
1. Support new device PO1
2. Support new device PT3SBT

Release Date: 2020-10-12
Release Date: 2020-11-12

### 20. V1.4.5

Expand All @@ -181,3 +181,10 @@ Release Date: 2020-12-11
2. Support new device HS2S

Release Date: 2021-01-14

### 21. V1.4.7

1. Support new device BG1S


Release Date: 2021-04-16
112 changes: 75 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,59 @@ npm install --save @ihealth/ihealthlibrary-react-native
yarn add @ihealth/ihealthlibrary-react-native
```

## Usage
#### Using React Native >= 0.60
Linking the package manually is not required anymore with [Autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md).

### Authentication
- **iOS Platform:**

#### Download license file
`$ npx pod-install` # CocoaPods on iOS needs this extra step

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.
![Download](./doc/download.png)
- **Android Platform with Android Support:**

#### Integrate license file
Using [Jetifier tool](https://github.com/mikehardy/jetifier) for backward-compatibility if needed

For iOS
As shown below, Add your license file to your iOS project.
![integrate ios](./doc/integrate-ios.png)
#### Using React Native < 0.60

For Android
As show below, Add your license file to your asserts folder.
![integrate android](./doc/integrate-android.png)
You then need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:

#### Using license file
```
react-native link @ihealth/ihealthlibrary-react-native
```

```js
import { iHealthDeviceManagerModule } from '@ihealth/ihealthlibrary-react-native';
If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):

// your license file
const filename = 'license.pem';
iHealthDeviceManagerModule.sdkAuthWithLicense(filename);
<details>
<summary>Manually link the library on iOS</summary>

Either follow the [instructions in the React Native documentation](https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking) to manually link the framework or link using [Cocoapods](https://cocoapods.org) by adding this to your `Podfile`:

```ruby
pod 'ihealth', :path => '../node_modules/@ihealth/ihealthlibrary-react-native'
```

### Troubleshooting
</details>

#### For Android
<details>
<summary>Manually link the library on Android</summary>

1. Check settings.gradle file in your android project and node_modules, make sure input the correct module path.
Make the following changes:

```gradle
#### `android/settings.gradle`
```groovy
include ':ihealthlibrary-react-native'
project(':ihealthlibrary-react-native').projectDir = new File(rootProject.projectDir,'../node_modules/@ihealth/ihealthlibrary-react-native/android')
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')
#### `android/app/build.gradle`
```groovy
dependencies {
...
implementation project(':ihealthlibrary-react-native')
}◊
```

3. Import iHealth module in your MainActivity.java
#### `android/app/src/main/.../MainActivity.java`
Import iHealth module in your MainActivity.java

```java
protected List<ReactPackage> getPackages() {
Expand All @@ -72,31 +76,65 @@ protected List<ReactPackage> getPackages() {
);
}
```
</details>

#### Android permissions

4. Location permission(in AndroidManifest.xml)
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" />
```

#### For iOS
## Usage

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
### Authentication

#### Download license file

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.
![Download](./doc/download.png)

#### Integrate license file

For iOS
As shown below, Add your license file to your iOS project.
![integrate ios](./doc/integrate-ios.png)

For Android
As show below, Add your license file to your asserts folder.
![integrate android](./doc/integrate-android.png)

#### Using license file

```js
import { iHealthDeviceManagerModule } from '@ihealth/ihealthlibrary-react-native';

// your license file
const filename = 'license.pem';
iHealthDeviceManagerModule.sdkAuthWithLicense(filename);
```

### Example

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.
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 shown below

```js
import { DeviceEventEmitter } from 'react-native';
import { iHealthDeviceManagerModule } from '@ihealth/ihealthlibrary-react-native';

componentDidMount() {
iHealthAPI.addListener();
DeviceEventEmitter.addListener(
iHealthDeviceManagerModule.Event_Authenticate_Result, (event) => { }
);
}

componentWillUnmount() {
iHealthAPI.removeListener();
DeviceEventEmitter.removeListener(iHealthDeviceManagerModule.Event_Authenticate_Result);
}
```

Expand Down
2 changes: 0 additions & 2 deletions android/.idea/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
api 'com.facebook.react:react-native:+'
api 'com.squareup.okhttp3:okhttp:4.8.0'
api 'com.google.code.gson:gson:2.8.6'
implementation files('libs/iHealthSDK_2.9.4.4.jar')
implementation files('libs/iHealthSDK_2.9.5.jar')
implementation 'org.greenrobot:greendao:3.2.2'
implementation 'no.nordicsemi.android:dfu:1.6.1'
implementation 'com.alibaba:fastjson:1.2.48'
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public void getOfflineData(String mac) {
}
}

@ReactMethod
public void setOfflineModel(String mac, boolean enable) {
Bg5sControl bg5sControl = getBg5sControl(mac);
if (bg5sControl != null) {
bg5sControl.setOfflineMeasurementMode(enable);
}
}

@ReactMethod
public void startMeasure(String mac, int measureType) {
Bg5sControl bg5sControl = getBg5sControl(mac);
Expand All @@ -120,7 +128,7 @@ public void adjustOfflineData(String mac, String timeString, String originData)
String offlineData = bg5sControl.adjustOfflineData(timeString, originData);
WritableMap params = Arguments.createMap();
params.putString(Bg5Profile.HISTORICAL_DATA_BG, offlineData);
params.putString("action", "action_get_offline_data");
params.putString("action", "action_adjust_offline_data");
sendEvent(EVENT_NOTIFY, params);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.module.annotations.ReactModule;
import com.ihealth.communication.control.Bg5Profile;
import com.ihealth.communication.control.Bg5sProfile;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -16,59 +17,43 @@ public class BG5SProfileModule extends ReactContextBaseJavaModule {
private static final String modelName = "BG5SProfileModule";
private static final String TAG = modelName;

private static final String ACTION_SET_TIME = "ACTION_SET_TIME";
private static final String ACTION_SET_UNIT = "ACTION_SET_UNIT";
private static final String ACTION_GET_BATTERY = "ACTION_GET_BATTERY";
private static final String ACTION_START_MEASURE = "ACTION_START_MEASURE";
private static final String ACTION_GET_OFFLINEDATA_COUNT = "ACTION_GET_OFFLINEDATA_COUNT";
private static final String ACTION_GET_OFFLINEDATA = "ACTION_GET_OFFLINEDATA";
private static final String ACTION_DELETE_OFFLINEDATA = "ACTION_DELETE_OFFLINEDATA";

private static final String ACTION_ERROR_BG = "ACTION_ERROR_BG";
private static final String ACTION_STRIP_IN = "ACTION_STRIP_IN";
private static final String ACTION_STRIP_OUT = "ACTION_STRIP_OUT";
private static final String ACTION_GET_BLOOD = "ACTION_GET_BLOOD";
private static final String ACTION_ONLINE_RESULT_BG = "ACTION_ONLINE_RESULT_BG";


private static final String GET_BATTERY = "GET_BATTERY";
private static final String GET_OFFLINEDATA_COUNT = "GET_OFFLINEDATA_COUNT";
private static final String GET_OFFLINEDATA = "GET_OFFLINEDATA";
private static final String SET_BOTTLEMESSAGE = "SET_BOTTLEMESSAGE";
private static final String START_MODE = "START_MODE";
private static final String GET_EXPIRECTIME = "GET_EXPIRECTIME";
private static final String GET_USENUM = "GET_USENUM";
private static final String GET_BOTTLEID = "GET_BOTTLEID";
private static final String ERROR_NUM_BG = "ERROR_NUM_BG";
private static final String ERROR_DESCRIPTION_BG = "ERROR_DESCRIPTION_BG";
private static final String ONLINE_RESULT_BG = "ONLINE_RESULT_BG";
private static final String DATA_ID = "DATA_ID";

/**
* Callback indicating the code analysis result.
*/
private static final String ACTION_CODE_ANALYSIS = "ACTION_CODE_ANALYSIS";


/**
* the strip number
*/
private static final String STRIP_NUM_BG = "STRIP_NUM_BG";


/**
* the expire time
*/
private static final String STRIP_EXPIRETIME_BG = "STRIP_EXPIRETIME_BG";


/**
* the bottle id
*/
private static final String BOTTLEID_BG = "BOTTLEID_BG";

private static final String ACTION_ERROR = "action_error";
private static final String ACTION_SET_TIME = "action_set_time";
private static final String ACTION_SET_UNIT = "action_set_unit";
private static final String ACTION_SEND_CODE = "action_send_code";
private static final String ACTION_DELETE_USED_STRIP = "action_delete_used_strip";
private static final String ACTION_DELETE_OFFLINE_DATA = "action_delete_offline_data";
private static final String ACTION_GET_OFFLINE_DATA = "action_get_offline_data";
private static final String ACTION_START_MEASURE = "action_start_measure";
private static final String ACTION_KEEP_LINK = "action_keep_link";
private static final String ACTION_STRIP_IN = "action_strip_in";
private static final String ACTION_GET_BLOOD = "action_get_blood";
private static final String ACTION_STRIP_OUT = "action_strip_out";
private static final String ACTION_RESULT = "action_result";
private static final String ACTION_GET_STATUS_INFO = "action_get_status_info";
private static final String ACTION_SET_OFFLINE_MEASUREMENT_MODE = "action_set_offline_measurement_mode";
private static final String ACTION_ENTER_CHARGED_STATE = "action_enter_charged_state";
private static final String ACTION_LEAVE_CHARGED_STATE = "action_leave_charged_state";
private static final String ACTION_GET_ALL_CONNECTED_DEVICES = "ACTION_GET_ALL_CONNECTED_DEVICES";

private static final String ERROR_NUM = "error_num";
private static final String ERROR_DESCRIPTION = "error_description";
private static final String INFO_BATTERY_LEVEL = "info_battery_level";
private static final String INFO_TIME = "info_time";
private static final String INFO_TIMEZONE = "info_timezone";
private static final String INFO_USED_STRIP = "info_used_strip";
private static final String INFO_OFFLINE_DATA_NUM = "info_offline_data_num";
private static final String INFO_CODE_VERSION_BLOOD = "info_code_version_blood";
private static final String INFO_CODE_VERSION_CTL = "info_code_version_ctl";
private static final String INFO_UNIT = "info_unit";
private static final String SEND_CODE_RESULT = "send_code_result";
private static final String OFFLINE_DATA = "offline_data";
private static final String DATA_TIME_PROOF = "data_time_proof";
private static final String DATA_MEASURE_TIME = "data_measure_time";
private static final String DATA_MEASURE_TIMEZONE = "data_measure_timezone";
private static final String DATA_VALUE = "data_value";
private static final String RESULT_VALUE = "result_value";
private static final String DATA_ID = "dataID";

public BG5SProfileModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -85,38 +70,44 @@ public Map<String, Object> getConstants() {

final Map<String, Object> constants = new HashMap<>();

constants.put(ACTION_SET_TIME, Bg5Profile.ACTION_SET_TIME);
constants.put(ACTION_SET_UNIT, Bg5Profile.ACTION_SET_UNIT);
constants.put(ACTION_GET_BATTERY, Bg5Profile.ACTION_BATTERY_BG);
constants.put(ACTION_START_MEASURE, Bg5Profile.ACTION_START_MEASURE);
constants.put(ACTION_GET_OFFLINEDATA_COUNT, Bg5Profile.ACTION_HISTORICAL_NUM_BG);
constants.put(ACTION_GET_OFFLINEDATA, Bg5Profile.ACTION_HISTORICAL_DATA_BG);
constants.put(ACTION_DELETE_OFFLINEDATA, Bg5Profile.ACTION_DELETE_HISTORICAL_DATA);
constants.put(ACTION_ERROR_BG, Bg5Profile.ACTION_ERROR_BG);
constants.put(ACTION_STRIP_IN, Bg5Profile.ACTION_STRIP_IN);
constants.put(ACTION_STRIP_OUT, Bg5Profile.ACTION_STRIP_OUT);
constants.put(ACTION_GET_BLOOD, Bg5Profile.ACTION_GET_BLOOD);
constants.put(ACTION_ONLINE_RESULT_BG, Bg5Profile.ACTION_ONLINE_RESULT_BG);

constants.put(ACTION_ERROR, Bg5sProfile.ACTION_ERROR);
constants.put(ACTION_SET_TIME, Bg5sProfile.ACTION_SET_TIME);
constants.put(ACTION_SET_UNIT, Bg5sProfile.ACTION_SET_UNIT);
constants.put(ACTION_SEND_CODE, Bg5sProfile.ACTION_SEND_CODE);
constants.put(ACTION_START_MEASURE, Bg5sProfile.ACTION_START_MEASURE);
constants.put(ACTION_DELETE_USED_STRIP, Bg5sProfile.ACTION_DELETE_USED_STRIP);
constants.put(ACTION_DELETE_OFFLINE_DATA, Bg5sProfile.ACTION_DELETE_OFFLINE_DATA);
constants.put(ACTION_GET_OFFLINE_DATA, Bg5sProfile.ACTION_GET_OFFLINE_DATA);
constants.put(ACTION_KEEP_LINK, Bg5sProfile.ACTION_KEEP_LINK);
constants.put(ACTION_STRIP_IN, Bg5sProfile.ACTION_STRIP_IN);
constants.put(ACTION_STRIP_OUT, Bg5sProfile.ACTION_STRIP_OUT);
constants.put(ACTION_GET_BLOOD, Bg5sProfile.ACTION_GET_BLOOD);
constants.put(ACTION_RESULT, Bg5sProfile.ACTION_RESULT);
constants.put(ACTION_GET_STATUS_INFO, Bg5sProfile.ACTION_GET_STATUS_INFO);
constants.put(ACTION_SET_OFFLINE_MEASUREMENT_MODE, Bg5sProfile.ACTION_SET_OFFLINE_MEASUREMENT_MODE);
constants.put(ACTION_ENTER_CHARGED_STATE, Bg5sProfile.ACTION_ENTER_CHARGED_STATE);
constants.put(ACTION_LEAVE_CHARGED_STATE, Bg5sProfile.ACTION_LEAVE_CHARGED_STATE);
constants.put(ACTION_GET_ALL_CONNECTED_DEVICES, iHealthBaseModule.ACTION_GET_ALL_CONNECTED_DEVICES);

constants.put(GET_BATTERY, Bg5Profile.BATTERY_BG);
constants.put(GET_OFFLINEDATA_COUNT, Bg5Profile.HISTORICAL_NUM_BG);
constants.put(GET_OFFLINEDATA, Bg5Profile.HISTORICAL_DATA_BG);
constants.put(SET_BOTTLEMESSAGE, Bg5Profile.SET_BOTTLE_MESSAGE);
constants.put(START_MODE, Bg5Profile.START_MODE_EXTRA);
constants.put(GET_EXPIRECTIME, Bg5Profile.GET_EXPIRECTIME);
constants.put(GET_USENUM, Bg5Profile.GET_USENUM);
constants.put(GET_BOTTLEID, Bg5Profile.GET_BOTTLEID);
constants.put(ERROR_NUM_BG, Bg5Profile.ERROR_NUM_BG);
constants.put(ERROR_DESCRIPTION_BG, Bg5Profile.ERROR_DESCRIPTION_BG);
constants.put(ONLINE_RESULT_BG, Bg5Profile.ONLINE_RESULT_BG);
constants.put(DATA_ID, Bg5Profile.DATA_ID);
constants.put(ERROR_NUM, Bg5sProfile.ERROR_NUM);
constants.put(ERROR_DESCRIPTION, Bg5sProfile.ERROR_DESCRIPTION);
constants.put(INFO_BATTERY_LEVEL, Bg5sProfile.INFO_BATTERY_LEVEL);
constants.put(INFO_TIME, Bg5sProfile.INFO_TIME);
constants.put(INFO_TIMEZONE, Bg5sProfile.INFO_TIMEZONE);
constants.put(INFO_USED_STRIP, Bg5sProfile.INFO_USED_STRIP);
constants.put(INFO_OFFLINE_DATA_NUM, Bg5sProfile.INFO_OFFLINE_DATA_NUM);
constants.put(INFO_CODE_VERSION_BLOOD, Bg5sProfile.INFO_CODE_VERSION_BLOOD);
constants.put(INFO_CODE_VERSION_CTL, Bg5sProfile.INFO_CODE_VERSION_CTL);
constants.put(INFO_UNIT, Bg5sProfile.INFO_UNIT);
constants.put(SEND_CODE_RESULT, Bg5sProfile.SEND_CODE_RESULT);
constants.put(OFFLINE_DATA, Bg5sProfile.OFFLINE_DATA);
constants.put(DATA_TIME_PROOF, Bg5sProfile.DATA_TIME_PROOF);
constants.put(DATA_MEASURE_TIME, Bg5sProfile.DATA_MEASURE_TIME);
constants.put(DATA_MEASURE_TIMEZONE, Bg5sProfile.DATA_MEASURE_TIMEZONE);
constants.put(DATA_VALUE, Bg5sProfile.DATA_VALUE);
constants.put(RESULT_VALUE, Bg5sProfile.RESULT_VALUE);
constants.put(DATA_ID, Bg5sProfile.DATA_ID);

constants.put(ACTION_CODE_ANALYSIS, "action_code_analysis");
constants.put(STRIP_NUM_BG, "strip_num");
constants.put(STRIP_EXPIRETIME_BG, "expire_time");
constants.put(BOTTLEID_BG, "bottle_id");
constants.put(ACTION_GET_ALL_CONNECTED_DEVICES, iHealthBaseModule.ACTION_GET_ALL_CONNECTED_DEVICES);
return constants;
}
}
Loading