# Setup

### Setup Auth/Config

Authenticates a user to be used with the SDK.

```swift
func setup(auth: MoveAuth, config: MoveConfig)
```

| **Parameters** |                                                                                                           |                              |
| -------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------- |
| auth           | [MoveAuth](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/models/moveauth#ios)     | User account object.         |
| config         | [MoveConfig](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/models/moveconfig#ios) | Move services configuration. |

### Update Config

Change the config originally passed in setup.

```swift
func update(config: MoveConfig)
```

| Parameters |                                                                                                           |                              |
| ---------- | --------------------------------------------------------------------------------------------------------- | ---------------------------- |
| config     | [MoveConfig](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/models/moveconfig#ios) | Move services configuration. |

Occasionally this functionality is needed for deployed apps when a projects configuration is updated on the backend.

{% hint style="warning" %}
**Precondition:** SDK user/config should be setup.
{% endhint %}

### Update authentication

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

```swift
func update(auth: MoveAuth, completion: ((MoveAuthError?) -> Void)? = nil)
```

| **Parameter** |                                                                                                                                                     |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| auth          | The user's updated [MoveAuth](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/models/moveauth#ios) object with the new token. |

| **Callback** |                                                                                                                                                                                                                   |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| completion   | Block that gets invoked on auth update completion with an optional [MoveAuthError](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/models/moveautherror#ios) for potential updating errors. |

{% hint style="warning" %}
**Precondition:** SDK user/config should be setup.
{% endhint %}

### **Get SDK Auth State**

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

```swift
func getAuthState() -> MoveAuthState
```

| **Return**                                                                                                      |                  |
| --------------------------------------------------------------------------------------------------------------- | ---------------- |
| [MoveAuthState](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/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/~/changes/1lLi1pFRKkteajbXv0hC/sdk/models/moveauthstate) changes.

```swift
func setAuthStateUpdateListener(_ listener: AuthStateCallback)
```

| **Callback**                                                                                                                                     |                                                                                                                                                                |
| ------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AuthStateCallback](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/models/listeners-callbacks#auth-state-update-listener) | Block that gets invoked every time [MoveAuthState](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/sdk/models/moveauthstate) is updated. |

{% hint style="warning" %}

### Authentication Expiry

The host app is expected to monitor [MoveAuthState](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/sdk/models/moveauthstate) updates via`authStateUpdateListener`(Android / [iOS](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/sdk/api-interface/services#set-sdk-auth-state-listener)) API and handle those changes accordingly.

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

### **Set SDK Initialization Listener**

Provide a block to be invoked when configuration fetch failed.

```swift
func setInitializationListener(_ listener: MoveInitializationCallback)
```

| **Callback**               |                                                                                    |
| -------------------------- | ---------------------------------------------------------------------------------- |
| MoveInitializationCallback | Block that gets invoked every time **configuration** fetch from the server failed. |

### Shutdown

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/~/changes/1lLi1pFRKkteajbXv0hC/sdk/models/movestate) will transit to `.uninitialized`.

```swift
func shutDown(force: Bool, _ callback: ((MoveShutdownResult) -> Void)?)
```

<table data-header-hidden><thead><tr><th width="139">Callback</th><th width="90"></th><th></th></tr></thead><tbody><tr><td><strong>Parameters</strong></td><td><strong>Default</strong></td><td></td></tr><tr><td>force</td><td>true</td><td>If true, <em>shutdown</em> executes immediately. Pending Data may be lost.</td></tr><tr><td>callback</td><td>nil</td><td>Returns a <a href="../../../models/moveshutdownresult#ios">MoveShutdownResult</a> upon completion. May fail if not forced.</td></tr></tbody></table>

{% hint style="warning" %}
**Precondition:** SDK user/config should be setup.
{% endhint %}
