> For the complete documentation index, see [llms.txt](https://docs.sentiance.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sentiance.com/getting-started/sdk-integration/5.-enabling-detections.md).

# 5. Enabling Detections

After creating a Sentiance user, you should enable SDK detections. This will allow the SDK to run in the background, and intelligently detect the user's movements patterns, driving habits, and other activities.

## Enable Detections

You can enable detections by calling <mark style="color:$success;">**`enableDetections()`**</mark>. Here are examples of how to do that on each platform:

{% tabs %}
{% tab title="iOS" %}
{% code expandable="true" %}

```swift
Sentiance.shared.enableDetections { result, error in
    guard let result = result else {
        NSLog("Failed to enable detections due to reason \(error!.failureReason)")
        return
    }
    
    NSLog("Successfully enabled detections")
}
```

{% endcode %}

After detections are successfully enabled, you can determine whether the SDK is able to detect, by checking the detection status:

```swift
switch result.detectionStatus { // or Sentiance.shared.detectionStatus
case .enabledAndDetecting:
    // Detections are enabled and running
case .enabledButBlocked:
    // Detections are enabled but blocked (e.g. missing permission issue)
default:
    // Other enum values don't apply for the success scenario
}
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val sentiance = Sentiance.getInstance(context)
sentiance.enableDetections().addOnCompleteListener { operation ->
    if (operation.isSuccessful) {
        Log.d(TAG, "Successfully enabled detections")
    } else {
        val error = operation.error;
        Log.e(TAG, "Failed to enabled detections due to reason {${error.reason}")
    }
}
```

After detections are successfully enabled, you can determine whether the SDK is able to detect, by checking the detection status:

```kotlin
val detectionStatus = operation.result.detectionStatus // or Sentiance.getInstance(context).detectionStatus
when (detectionStatus) {
    DetectionStatus.ENABLED_AND_DETECTING -> 
        // Detections are enabled and running
    DetectionStatus.ENABLED_BUT_BLOCKED ->
        // Detections are enabled but blocked (e.g. missing permission issue)
    else ->
        // Other enum values don't apply for the success scenario
}
```

{% endtab %}

{% tab title="React Native" %}

```typescript
import { enableDetections } from '@sentiance-react-native/core';
try {
    const result = await enableDetections();
    console.log(`SDK detection status is now ${result.detectionStatus}`);
} catch(e) {
    console.log('Failed to start detections: ' + e);
}
```

After detections are successfully enabled, you can determine whether the SDK is able to detect, by checking the detection status:

```typescript
const detectionStatus = result.detectionStatus;

switch(detectionStatus) {
    case 'ENABLED_AND_DETECTING':
        // Detections are enabled and running
        break;
    case 'ENABLED_BUT_BLOCKED':
        // Detections are enabled but blocked (e.g. missing permission issue)
        break;
    default:
        // Other enum values don't apply for the success scenario
}
```

{% endtab %}

{% tab title="Flutter" %}

```dart
final sentiance = SentianceCore();

try {
    await sentiance.enableDetections();
    print("Detections are now enabled.");
} on EnableDetectionsError catch (e) {
    print('Failed to enable detections, reason: ${e.reason}');
} catch (e) {
    print(e);
}
```

After detections are successfully enabled, you can determine whether the SDK is able to detect, by checking the detection status:

```dart
final sdkStatus = await sentiance.getSdkStatus();
switch (sdkStatus.detectionStatus) {
    case DetectionStatus.enabledAndDetecting:
    // Detections are enabled and running
    case DetectionStatus.enabledButBlocked:
    // Detections are enabled but blocked (e.g. missing permission issue)
    default:
    // Other enum values don't apply for the success scenario
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Enabling Detections Is Persistent**

When you enable detections, the SDK will remember this and automatically enable them the next time the app restart. Therefore, you do not need to enable them every time. You only need to make sure that you are properly initializing the SDK during every app startup.
{% endhint %}

If the resulting detection status is "**enabled and detecting**", then detections are successfully running. However, if the status is "**enabled but blocked**", then an issue is preventing detections from starting. Once the issue is resolved, detection will start running automatically. Most likely causes for blocked detection are:

* Missing permission.
* Location service disabled on the device.
* OS restrictions, such as background execution restriction on Android.
* Device is in airplane mode.
* The user account is deactivated.

To find out the exact reason, head over to [the next section](/getting-started/sdk-integration/6.-sdk-status-updates.md) to learn about how you can check the SDK's status.
