# Initialization

The MOVE SDK must be initialized natively. For the first init, the SDK expects to be setup after user onboarding using Javascript. In this case, Javascript passes the required auth code or [MoveAuth](https://docs.movesdk.com/move-platform/sdk/models/moveauth), and [MoveConfig](https://docs.movesdk.com/move-platform/sdk/models/moveconfig) objects.

In all future inits, the SDK expects to be initialized natively at app start points (In AppDelegate for iOS, and MainApplication for Android). This is to guarantee that the MOVE SDK is set up and active before the limited time provided by the OS in background wakeups is consumed.&#x20;

The native init will re-use the last authentication and configs objects passed to the SDK from the JS initialization.

### Expo

{% hint style="info" %}
Added in SDK 2.16.
{% endhint %}

When using *expo* the following iOS/Android sections can be skipped and replaced by adding the Move SDK as a plugin in your `app.config.js`:

```js
plugins: [
  ["react-native-move-sdk", {
    "extensions": [
      "Health" // optional
    ]
  }],
	...
]
```

Optional extensions

Pass `"extensions": []` otherwise.

<table><thead><tr><th width="137.1015625">Extension</th><th>Comment</th></tr></thead><tbody><tr><td><code>"Health"</code></td><td>Used for Health Steps service, enables HealthKit functionality. When using this, make sure the app is properly setup to use Health APIs for each platform. See <a href="../../appendix/react-native/permission-handling">Appendix</a>.</td></tr></tbody></table>

### iOS

~~To initialize the SDK natively, in your AppDelegate:~~

{% hint style="danger" %}
Removed in SDK 2.14. Only for 2.13 and bellow.
{% endhint %}

```objectivec
#import <ReactMoveSDK/MoveSdk.h>
...
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [RCTMoveSdk initIfPossibleWithLaunchOptions:launchOptions];
  return YES;
}
```

### Android

To initialize the SDK natively, in your MainApplication:

```java
import com.movesdk.NativeMoveSdkWrapper;
...
public class MainApplication extends Application implements ReactApplication {
	private NativeMoveSdkWrapper sdkWrapper;
	...
	public void onCreate() {
		super.onCreate();
		sdkWrapper = NativeMoveSdkWrapper.getInstance(this);
		sdkWrapper.init(this);
		...
	}
}
```

or using Kotlin

```kotlin
package your.package.name
import com.movesdk.NativeMoveSdkWrapper
// ...

class MainApplication : Application(), ReactApplication {
    private lateinit var sdkWrapper: NativeMoveSdkWrapper
    // ...
    override fun onCreate() {
        super.onCreate()
    	sdkWrapper = NativeMoveSdkWrapper.getInstance(this)
    	sdkWrapper.init(this)
        // ...
    }
    // ...
}
```

When using the Health Service, you must register the permission handler in your activity:

```kotlin
package your.package.name
import com.movesdk.NativeMoveSdkWrapper
// ...

class MainActivity : ReactActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // ...
        NativeMoveSdkWrapper.getInstance(this.applicationContext).registerRequestPermissionLauncher(this)
        super.onCreate(null)
    }
}
```

### Javascript

To setup the SDK in React Native you have to provide and auth code (provided by the backend), [**MoveSdkConfig**](https://docs.movesdk.com/move-platform/sdk/models/moveconfig#react-native) and [**MoveSdkAndroidConfig**](https://docs.movesdk.com/move-platform/~/changes/1lLi1pFRKkteajbXv0hC/sdk/models/movesdkandroidconfig)**.** [**MoveSdkOptions**](https://docs.movesdk.com/move-platform/sdk/models/moveoptions) is optional object with additional SDK configurations.

```javascript
MoveSdk.setupWithCode(
    code: string,
    config: MoveSdkConfig,
    android: MoveSdkAndroidConfig,
    options: MoveSdkOptions
) => Promise<void>
```

Setup will return with a promise or throw an error on failure, such as when the code is expired or there is no network available. These errors must be caught.

Previously setup was done using a [**MoveSdkAuth**](https://docs.movesdk.com/move-platform/sdk/models/moveauth#react-native) objec&#x74;**.**

```javascript
MoveSdk.setup(
    config: MoveSdkConfig,
    auth: MoveSdkAuth,
    android: MoveSdkAndroidConfig,
    options: MoveSdkOptions
) => Promise<void>
```

{% hint style="warning" %}
Will be removed in future versions, use `setupWithCode(...)` instead.
{% endhint %}

### Next steps

The SDK will provide all relevant information on its status and ability to recognise trips. In order to have up-to-date information about the status of the SDK you can add [listeners](https://docs.movesdk.com/move-platform/sdk/models/listeners-callbacks) (e.g. [addSdkStateListener](https://docs.movesdk.com/move-platform/sdk/models/listeners-callbacks#sdk-state-listener) to be aware of every [MoveSDKState](https://docs.movesdk.com/move-platform/sdk/models/movestate) change, [addTripStateListener](https://docs.movesdk.com/move-platform/sdk/models/listeners-callbacks#trip-state-listener) to be aware of every [MoveTripState](https://docs.movesdk.com/move-platform/sdk/models/movetripstate) change) or request this information directly (e.g. [getState](https://docs.movesdk.com/move-platform/sdk/api-interface/react-native/services#get-sdk-state) and [getTripState](https://docs.movesdk.com/move-platform/sdk/api-interface/react-native/services#get-trip-state)).

In addition, the SDK will report all possible [errors](https://docs.movesdk.com/move-platform/sdk/models/moveservicefailure) and [warnings](https://docs.movesdk.com/move-platform/sdk/models/moveservicewarning) that may prevent the SDK from functioning properly. Among these errors and warnings will be those that indicate a missing permission or incomplete guarantee of certain permission. This is useful for informing the user of certain problems in granting permissions to the host app. To keep track of these errors and warnings you can use listeners ([addErrorsListener](https://docs.movesdk.com/move-platform/sdk/api-interface/react-native/services#set-errors-listener) and [addWarningsListener](https://docs.movesdk.com/move-platform/sdk/api-interface/react-native/services#set-warnings-listener)) or request a list of errors or warnings directly ([getErrors](https://docs.movesdk.com/move-platform/sdk/api-interface/react-native/services#get-errors) and [getWarnings](https://docs.movesdk.com/move-platform/sdk/api-interface/react-native/services#get-warnings)).

{% hint style="info" %}
Also note that for better efficiency all listeners should be added before initialising the SDK. With this approach it's easier to track down and fix all errors and problems, that could be triggered by initialisation or occurred even before initialisation.
{% endhint %}
