Purpose of this package is to allow communication between Garmin Device and React Native app. It requires custom Garmin app to send messages that can be received by React Native app.
Check out my presentation at RN EU 2023
https://www.youtube.com/watch?v=CRQOkie6Ej8
npm install react-native-garmin-connect
or
yarn add react-native-garmin-connect
First, initialize Garmin SDK using initGarminSDK
function.
Url schema is required for ios in order to get devices list from Garmin Connect.
initGarminSDK("YOUR_CUSTOM_URL_SCHEMA")
Remember to cleanup it on app closing with destroy
.
To work with Garmin SDK, it's required to have Garmin Connect installed. It gets data about devices from Garmin's mobile app.
To get list of devices attached to your account, simply call:
showDevicesList()
When working with iOS there is an inconvinience, to get devices list, you need to get it through url schema. Requesting data is done with:
showDevicesList()
They it follows the same pattern as Android.
showDevicesList()
Due to another iOS limitation, when connecting to device, function requires to pass it's id, model and name.
connectDevice(id, model, name)
Sending message from mobile app to Garmin device is done with:
sendMessage(message)
To interact with SDK, certain events are being send:
onSdkReady
- send after SDK initialization
onMessage
- send when received message from Garmin device
onError
- send when SDK encounters error
onInfo
- send when SDK finds that Garmin Connect app is not installed
Way to handle them is to define event emitter:
import { Platform, NativeEventEmitter, DeviceEventEmitter } from 'react-native';
import { GarminConnect } from 'react-native-garmin-connect';
const emitter = useMemo(() => {
if (Platform.OS === 'ios') {
return new NativeEventEmitter(GarminConnect);
}
return DeviceEventEmitter;
}, []);
emitter.addListener('onSdkReady', yourFunction);
New architecture is supported for both platforms.
Docs can be found here.
Example app can be found in example it works with Garmin app.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library