React Native wrapper for MDD SDK
npm install react-native-mdd-locate-sdk
You don't need to do anything to deal with library requirements, those will be handled automatically for you.
You will need to set up permissions in order to make this work, and which ones you need will be dependent on the react-native versions you are trying to support. Please make sure that you have the following permissions granted in order to use the library propery:
- BLUETOOTH
- BLUETOOTH_ADMIN
- BLUETOOTH_SCAN
- ACCESS_COARSE_LOCATION
- ACCESS_FINE_LOCATION
- INTERNET
- POST_NOTIFICATIONS
To ensure your app functions correctly with the MddLocateSDK:
-
Open your app's
Info.plist
. -
Add a new entry with the key
NSLocationWhenInUseUsageDescription
. -
Set the value to a string describing why your app needs location access. For instance:
<key>NSLocationWhenInUseUsageDescription</key> <string>We use your location to provide beacon scanning functionality related to vehicles in your vicinity.</string>
-
Open your project settings by clicking on the project name in the Project Navigator.
-
Select the app target from the list of targets.
-
Navigate to the "Signing & Capabilities" tab.
-
In the "Background Modes" section, check the boxes for
Location updates
andUses Bluetooth LE accessories
.
This SDK provides a React Native interface for the MDD SDK, allowing you to interact with MDD services on both Android and iOS platforms.
import { startTrackingTags, stopTrackingTags, addReadHandler } from 'react-native-mdd-locate-sdk';
// Start tracking tags for a user
await startTrackingTags('your-api-key', 'username');
// Add a handler for read events
addReadHandler((event) => {
console.log('Read event:', event);
});
// Get the current API key
const apiKey = await getApiKey();
console.log('Current API key:', apiKey);
// Stop tracking tags
const stopped = await stopTrackingTags();
console.log('Tracking stopped:', stopped);
Setting this up will allow the SDK to track tags that are available in bluetooth range of the phone and report them automatically to the MDD API.
import { startDetecting, stopDetecting, addProximityUpdateHandler } from 'react-native-mdd-locate-sdk';
// Start detecting a specific tracking tag
const started = await startDetecting('tracking-tag-id');
console.log('Detection started:', started);
// Add a handler for proximity updates
addProximityUpdateHandler((event) => {
console.log('Proximity update:', event.proximity);
});
// Stop detecting a specific tracking tag
const stopped = await stopDetecting('tracking-tag-id');
console.log('Detection stopped:', stopped);
This does not actually report to the API, but allows you to find a tag by indicating how close the tag is to a phone. Possible proximity values are: 'unknown', 'near', 'immediate', 'far'.
Gets the currently configured API key.
- Returns: A promise that resolves to the current API key
Starts tracking tags for the specified username using the provided API key.
-
Parameters:
-
apiKey
- Your MDD SDK API key -
username
- The username to associate with tag tracking
-
- Returns: A promise that resolves when tracking has started
Stops tracking tags.
-
Returns: A promise that resolves to
true
if tracking was successfully stopped
Adds a handler for read events.
-
Parameters:
fn
- A function that will be called with read events
Starts detecting the specified tracking tag.
-
Parameters:
trackingTagId
- The ID of the tracking tag to detect -
Returns: A promise that resolves to
true
if detection was successfully started
Stops detecting the specified tracking tag.
-
Parameters:
trackingTagId
- The ID of the tracking tag to stop detecting -
Returns: A promise that resolves to
true
if detection was successfully stopped
addProximityUpdateHandler(fn: (event: { proximity: 'unknown' | 'near' | 'immediate' | 'far' }) => void): void
Adds a handler for proximity updates.
-
Parameters:
fn
- A function that will be called with proximity update events
The SDK includes built-in error handling for common issues such as missing native modules. If you encounter a linking error, ensure that:
- You have run 'pod install' (for iOS)
- You have rebuilt the app after installing the package