# Listeners/Callbacks

## Initialize Listener

Triggers if [MoveConfigurationError](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) occurs on initialization ([Android](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/android-1/builder#DolphinSdk.Builderv1.1-initializationInitializationlistener)/[iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/intialization#definition)).

{% tabs %}
{% tab title="Android" %}

```kotlin
interface InitializeListener {
    fun onError(error: MoveConfigurationError)
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
typealias MoveIntializationCallback = ((_ confgError: MoveConfigurationError?) -> Void)?
```

{% endtab %}
{% endtabs %}

| **Parameter**                                                                                     |                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [MoveConfigurationError](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) | Potiential [MoveConfigurationError](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) on initilazation ([Android](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/android-1/builder#DolphinSdk.Builderv1.1-initializationInitializationlistener)/[iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/intialization#definition)). |

## SDK State Listener

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

{% hint style="info" %}
Set an SDK State listener using`setSDKStateListener`([Android](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/android-1/builder#DolphinSdk.Builderv1.1-sdkstatelistenerSdkstatelistener)/[iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#set-sdk-state-listener)) API to anticipate handling the SDK State changes, start detection services when [MoveSDKState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movestate) is `.ready` or handle`.error` if occurred.
{% endhint %}

{% tabs %}
{% tab title="Android" %}

```kotlin
interface StateListener {
    fun onStateChanged(sdk: MoveSdk, state: MoveSdkState)
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
typealias MoveSDKStateCallback = (_ state: MoveSDKState) -> Void
```

{% endtab %}
{% endtabs %}

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

## Auth State Update Listener

Triggers whenever the [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) changes.

{% 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`authStateUpdateListener`([Android](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/android-1/builder#DolphinSdk.Builderv1.1-initializationInitializationlistener-1) / [iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#set-sdk-auth-state-listener)) API and handle those changes accordingly.

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

{% tabs %}
{% tab title="Android" %}

```kotlin
interface AuthStateUpdateListener {
    fun onAuthStateUpdate(state: MoveAuthState)
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
typealias MoveAuthStateCallback = (_ state: MoveAuthState) -> Void
```

{% endtab %}
{% endtabs %}

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

## Trip State Listener

Triggers whenever the [MoveTripState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movetripstate) changes.

{% tabs %}
{% tab title="Android" %}

```kotlin
interface TripStateListener {
    fun onTripStateChanged(sdk: MoveSdk, tripState: MoveTripState)
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
typealias MoveTripStateCallback = (_ tripState: MoveTripState) -> Void
```

{% endtab %}
{% endtabs %}

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

## Trip Metadata Provider

Triggers whenever a trip is ending, for the host app to append metadata along with that trip if needed.

{% tabs %}
{% tab title="Android" %}

```kotlin
interface TripMetadataProvider {
    fun provideMetadata(start: Long, end: Long): Map<String, String>
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
typealias MoveMetaDataCallback = (_ tripStart: Date, _ tripEnd: Date) -> [String: String]
```

{% endtab %}
{% endtabs %}

| **Parameter**   |           |                            |
| --------------- | --------- | -------------------------- |
| start/tripStart | Long/Date | Trip start timestamp/date. |
| end/tripEnd     | Long/Date | Trip end timestamp/date.   |

| **Return**                                  |
| ------------------------------------------- |
| A String dictionary of the trip's metadata. |

## Device Status Callback

Triggers whenever [MoveDeviceStatus](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movedevicestatus) changes.

{% tabs %}
{% tab title="iOS" %}

```swift
typealias MoveDeviceStatusCallback = (_ status: MoveDeviceStatus) -> Void
```

{% endtab %}
{% endtabs %}

| **Parameter**                                                                                       |                                                                                                             |
| --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| [MoveDeviceStatus](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movedevicestatus) | Latest [MoveDeviceStatus](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/movedevicestatus). |

## Log Callback

Triggers whenever a new log event occurs.

{% tabs %}
{% tab title="iOS" %}

```swift
typealias MoveLogCallback = (_ log: String) -> Void
```

{% endtab %}
{% endtabs %}

| **Parameter** |        |                |
| ------------- | ------ | -------------- |
| log           | String | New log event. |
