React Native
React Native library for integrating WeFitter and Samsung Health into your app
- This library is written for React Native CLI. Expo Go is unsupported
Installation
yarn add https://github.com/wefitter/react-native-wefitter-samsung.git#v2.0.0
Add wefitter-shealth-2.0.0.aar
and samsung-health-data-1.5.0.aar
to libs
folder which should normally be in app/libs
. These files can be found in node_modules/react-native-wefitter-samsung/android/libs
in your protect or here. Make sure you select the same version tag you are using in your app before downloading to prevent incompatibility issues. See the table at the bottom of this page to help you find the right version.
Add the following dependencies to your app/build.gradle
:
Hide code example
dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar'])
}
Hide code example
import WeFitterSamsung, {
ConfiguredEvent,
ConnectedEvent,
ErrorEvent,
} from 'react-native-wefitter-samsung';
// ...
const [connected, setConnected] = useState<boolean>(false);
useEffect(() => {
if (Platform.OS === 'android') {
// create native event emitter and event listeners to handle status updates
const emitter = new NativeEventEmitter();
const configuredListener = emitter.addListener(
'onConfiguredWeFitterSamsung',
(event: ConfiguredEvent) =>
console.log(`WeFitterSamsung configured: ${event.configured}`)
);
const connectedListener = emitter.addListener(
'onConnectedWeFitterSamsung',
(event: ConnectedEvent) => {
console.log(`WeFitterSamsung connected: ${event.connected}`);
setConnected(event.connected);
}
);
const errorListener = emitter.addListener(
'onErrorWeFitterSamsung',
(event: ErrorEvent) => {
console.log(`WeFitterSamsung error: ${event.error}`);
// `error` can be checked to override specific messages
// `forUser` boolean indicates the error requires user interaction
if (event.forUser) {
Alert.alert('', event.error, [
{
text: 'OK',
onPress: () => {
// `tryToResolveError` will guide the user on fixing certain errors
// for example:
// - link to the app store to install or update Samsung Health
// - open Samsung Health to accept privacy policy
// - open Settings when Samsung Health needs to be enabled
WeFitterSamsung.tryToResolveError(event.error);
},
},
]);
}
}
);
// create config
const config = {
token: 'YOUR_TOKEN', // required
apiUrl: 'YOUR_API_URL', // required, the url should be base without `v1/ingest/` as the library will append this. For example: `https://api.wefitter.com/api/`
startDate: 'CUSTOM_START_DATE', // optional with format `yyyy-MM-dd`, by default data of the past 20 days will be uploaded
notificationTitle: 'CUSTOM_TITLE', // optional
notificationText: 'CUSTOM_TEXT', // optional
notificationIcon: 'CUSTOM_ICON', // optional, e.g. `ic_notification` placed in either drawable, mipmap or raw
notificationChannelId: 'CUSTOM_CHANNEL_ID', // optional
notificationChannelName: 'CUSTOM_CHANNEL_NAME', // optional
};
// configure WeFitterSamsung
WeFitterSamsung.configure(config);
return () => {
configuredListener.remove();
connectedListener.remove();
errorListener.remove();
};
}
return;
}, []);
const onPressConnectOrDisconnect = () => {
if (Platform.OS === 'android') {
connected ? WeFitterSamsung.disconnect() : WeFitterSamsung.connect();
} else {
Alert.alert('Not supported', 'WeFitterSamsung is not supported on iOS');
}
};
Compatibility
react-native-wefitter-samsung | wefitter-shealth | samsung-health-data |
---|---|---|
v2.0.0 | 2.0.0 | 1.5.0 |
v1.5.1 | 1.5.1 | 1.5.0 |
v1.5.0 | 1.5.0 | 1.5.0 |
v1.4.0 | 1.4.0 | 1.5.0 |
v1.3.0 | 1.3.0 | 1.5.0 |
v1.2.0 | 1.2.0 | 1.5.0 |
v1.1.0 | 1.1.0 | 1.5.0 |
v1.0.0 | 1.0.0 | 1.5.0 |
v0.0.2 | 0.0.3 | 1.5.0 |
v0.0.1 | 0.0.2 | 1.5.0 |