Add Features
Get User's Install ID
Each time the SDK is installed on a user's device, it creates a unique installId
. The returned value will be a Promise<string>
. This can be used to allow your users to submit Data Erasure Requests or for debugging in our Event Logs tool in your developer console. Example usage:
import MovementSdk from '@foursquare/movement-sdk-react-native';
import React, {useState, useEffect} from 'react';
import {Text} from 'react-native';
export default () => {
const [installId, setInstallId] = useState('-');
useEffect(() => {
(async () => {
setInstallId(await MovementSdk.getInstallId());
})();
});
return (
<React.Fragment>
<Text>Install ID: {installId}</Text>
</React.Fragment>
);
};
Get User's Current Location
You can actively request the current location of the user by calling the MovementSdk.getCurrentLocation
method. The return value will be a Promise<CurrentLocation>
. The CurrentLocation
object has the current venue the device is most likely at as well as any geofences that the device is in (if configured). Find more information for Android and for iOS.
Example usage:
import MovementSdk, {
CurrentLocation,
} from '@foursquare/movement-sdk-react-native';
import React, {useEffect, useState} from 'react';
import {Alert, Text} from 'react-native';
export default () => {
const [currentLocation, setCurrentLocation] = useState<CurrentLocation>();
useEffect(() => {
async () => {
try {
setCurrentLocation(await MovementSdk.getCurrentLocation());
} catch (e) {
Alert.alert('Movement SDK', `${e}`);
}
};
});
if (currentLocation != null) {
const venue = currentLocation.currentPlace.venue;
const venueName = venue?.name || 'Unnamed venue';
return (
<React.Fragment>
<Text>Venue: {venueName}</Text>
</React.Fragment>
);
} else {
return (
<React.Fragment>
<Text>Loading...</Text>
</React.Fragment>
);
}
};
Passive Location Detection
Passive location detection is controlled with the MovementSdk.start
and MovementSdk.stop
methods. When started, the SDK will send notifications to Webhooks and other third-party integrations.
Example usage:
import {Alert, Button} from 'react-native';
import MovementSdk from '@foursquare/movement-sdk-react-native';
import React from 'react';
export default () => {
const startMovement = async function () {
const canEnable = await MovementSdk.isEnabled();
if (canEnable) {
MovementSdk.start();
Alert.alert('Movement SDK', 'Movement SDK started');
} else {
Alert.alert('Movement SDK', 'Error starting');
}
};
const stopMovement = function () {
MovementSdk.stop();
Alert.alert('Movement SDK', 'Movement SDK stopped');
};
return (
<React.Fragment>
<Button title="Start" onPress={() => startMovement()} />
<Button title="Stop" onPress={() => stopMovement()}
/>
</React.Fragment>
);
};
Note: If you wish to handle background notifications locally on the device, you will need to add the notification handler and delegate in the native piece of each platform, as mentioned in the Installation instructions.
User Info
For partners utilizing the server-to-server method for visit notifications, user info can be passed with the method MovementSdk.setUserInfo
.
import MovementSdk, {
UserInfoUserIdKey,
UserInfoGenderKey,
UserInfoBirthdayKey,
UserInfoGenderMale,
} from '@foursquare/movement-sdk-react-native';
import {useEffect} from 'react';
export default () => {
useEffect(() => {
(async () => {
MovementSdk.setUserInfo(
{
[UserInfoUserIdKey]: 'userId',
[UserInfoGenderKey]: UserInfoGenderMale,
[UserInfoBirthdayKey]: new Date(2000, 0, 1).getTime(),
otherKey: 'otherVal',
},
true,
);
})();
}, []);
};
Updated almost 2 years ago