# Services

```javascript
import MoveSdk from 'react-native-move-sdk';
```

## **Detection Services**

### **Start Automatic Detection**

Starts the required detection services stated in the [MoveConfig](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveconfig) passed on initialization. Starting the service will set the [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) to `.running`.

{% hint style="warning" %}
**Precondition**: SDK should be in`.ready`[MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate)
{% endhint %}

```jsx
startAutomaticDetection: () => void
```

### **Stop Automatic Detection**

Stops the automatic detection service, including all SDK services like driving detection, points of interest, walking and places. Stopping the service will set the [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) back to `.ready`.&#x20;

{% hint style="warning" %}
**Precondition**: SDK should be in`.running`[MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).
{% endhint %}

```jsx
stopAutomaticDetection: () => void
```

### **Force Trip Recognition**

Temporarily calibrates the SDK to the highest detection mode.

In order to optimize battery consumption, the SDK goes through different detection modes with different battery consumption levels, depending on the user's current behavior and activity. In general, the SDK is responsible for alternating between those different detection modes.&#x20;

The SDK also provides hosting apps this API to call if they have their own reasons (like buttons, sensors or beacons) to believe that the user is starting a trip. This will make sure the SDK is on the highest detection state to detect the trip faster.

{% hint style="warning" %}
&#x20;**Precondition**: SDK should be in`.running` [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).
{% endhint %}

```jsx
forceTripRecognition: () => void
```

### **Finish Current Trip**

Ends the current ongoing trip.

This API will end the ongoing trip and set [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) back to `.idle`. The SDK is responsible for detecting the trip start and end points. The SDK also provides hosting apps this API to call if they have their own reasons (like sensors or beacons) to believe that the user's trip has ended.

{% hint style="warning" %}
**Precondition**:[ MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) should be in an active trip.
{% endhint %}

```jsx
finishCurrentTrip: () => void
```

{% hint style="info" %}
If this API is called while the user is active on a driving trip, a new trip will start again right away. If the intention is to un-track the ongoing trip, call `ignoreCurrentTrip`API.

More information about trip states can be found in [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate).
{% endhint %}

### **Ignore Current Trip**

Ignores the current ongoing trip.&#x20;

This API will set the ongoing [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) to `.ignored`. Data of ignored trips is purged and not sent to the server.

{% hint style="warning" %}
**Precondition**: [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) should be in an active trip.
{% endhint %}

```jsx
ignoreCurrentTrip: () => void
```

## Processing Services

### **Keep in foreground (Android only)**

When an Android application is in the background it may receive limited data (location, sensors, etc.). To improve this behavior, it is possible to put the application always in the foreground with a visible notification that cannot be discarded. Just because it's visible it doesn't mean that it is performing any data collection at all. So this should not have any significant battery impact at all.

{% hint style="info" %}
Disabled by default.
{% endhint %}

{% hint style="warning" %}
Since it may be annoying to the user, it should only be enabled in case of problems.
{% endhint %}

```jsx
keepInForeground: (enabled: boolean) => void
```

### **Keep active (Android only)**

To save battery consumption, the SDK is using several triggers to start its data listeners. In case of trouble, these triggers can be circumvented by allowing the MoveSdk to stay active all the time. In that case the SDK is always monitoring required data and is therefore consuming more battery. Depending on the configuration, it may happen that the notification (see[ notification handling](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/appendix/android/notification-managment)) is always visible to the user.

{% hint style="info" %}
Disabled by default.
{% endhint %}

{% hint style="warning" %}
Since this is consuming more battery, it should only be enabled in case of problems.
{% endhint %}

```jsx
keepActive: (enabled: boolean) => void
```

### **Get SDK State**

Gets the current[ MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate).

```jsx
getState: () => Promise<SdkState>
```

| **Return**                                                                               |                  |
| ---------------------------------------------------------------------------------------- | ---------------- |
| [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) | Latest SDK State |

### **Set SDK State Listener**

Provide a block to be invoked every time [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) changes.

{% hint style="info" %}
Set the [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) listener before initializing the SDK to anticipate the SDK [State](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) changes triggered by the initialization API. \
Here the host app can start the SDK services when [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) is`.ready`or handle errors if occurred.
{% endhint %}

```jsx
addSDKStateListener: (
    sdkStateChanged: (event: SdkStateEvent) => void
) => ListenerSubscription
```

| **Callback**    |                                                                                                                                                                                                                                                            |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| sdkStateChanged | Block that gets invoked every time[ MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) is changed and provides the updated [ MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate). |

### **Get SDK Auth State**

Gets the current [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate).

```swift
```

| **Return**                                                                                    |                  |
| --------------------------------------------------------------------------------------------- | ---------------- |
| [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate) | Latest SDK State |

### **Set SDK Auth State Listener**

Provide a block to be invoked every time [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate) changes.

```swift
addAuthStateListener: (
    authStateChanged: (event: AuthStateEvent) => void
) => ListenerSubscription
```

| **Callback**     |                                                                                                                                              |
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| authStateChanged | Block that gets invoked every time [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate) is updated. |

{% hint style="warning" %}

### Authentication Expiry

The host app is expected to monitor [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate) updates via`authStateUpdateListene` API and handle those changes accordingly.

Check [Authentication updates and expiry](https://docs.movesdk.com/move-platform/move-sdk-1.x/models/moveauthstate#authentication-updates-and-expiry) for more details about authentication expiry and renewal.
{% endhint %}

### **Get Trip State**

&#x20;Gets the current [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate).

```jsx
getTripState: () => Promise<TripState>
```

| **Return**                                                                                    |                                                                                                       |
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) | Current [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) |

### **Set Trip State Listener**

Provide a block to be invoked every time [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) changes.

```jsx
addTripStateListener: (
    tripStateChanged: (state: TripState) => void
) => ListenerSubscription
```

| Callback         |                                                                                                                                                                                                                                                                       |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| tripStateChanged | Block that gets invoked every time  [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) is changed and provides the updated  [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate). |

### **Shutdown SDK**

Shutdown SDK shared instance.

Stops SDK services, send the queued user data, and de-initializes the SDK. After that is executed,  the [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) will transit to `.uninitialized`.

{% hint style="warning" %}
**Precondition:** SDK should be initialized.
{% endhint %}

```jsx
shutdown: () => void
```

### **Synchronize User Data**

Used to force synchronizing user data with the SDK server. Limited to once per 2 minutes.

```jsx
synchronizeUserData: () => void
```

## Configuration services

### Update authentication

Updates SDK [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth). On SDK auth expiry, the authStateListener will trigger expired state. The host app is expected to fetch a new [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) using its product API key and pass it to the MoveSDK using the following API:

```jsx
updateAuth: (auth: MoveSdkAuth) => Promise<void>
```

<table><thead><tr><th width="186.4285714285714">Parameters</th><th width="150"> </th></tr></thead><tbody><tr><td>auth</td><td>The user's updated Auth object with the new token.</td></tr></tbody></table>
