# Crash Detection

## Principle

Crash detection features, included into the DriveKit Trip Analysis component, is able to collect and analyse smartphone sensors data to automatically detect when a car accident occurs.&#x20;

DriveKit Trip Analysis analyzes signals from the GPS sensor and also from the motion sensors (accelerometer, gyrometer and magnetometer).&#x20;

This feature is enabled if the following conditions are fulfilled:

* Your API key has the access rights to use this service;&#x20;
* You have enabled the feature by following the instructions described in this section;&#x20;
* A trip has been detected and is being analysed.&#x20;
* The smartphone's sensors are functional.&#x20;
* The SDK is able to check the status of the required sensors.

The crash detection steps are:

1. A trip is detected automatically or started manually and the trip recording starts.&#x20;
2. The crash feature detects a potential collision based on motion sensors.&#x20;
3. The GPS and motion data are pushed to the backend analysis services in charge of the signal processing and crash confirmation.&#x20;
4. The SDK receives a crash analysis service response with a status.&#x20;
5. If the crash is confirmed, the Trip analysis component can display a survey to ask the driver whether he needs assistance. This is an optional feature.

## **Enable crash detection**

If the crash detection configuration is enabled for your company, your API key carries out the feature access and the crash detection will be enabled accordingly.&#x20;

However, you can deactivate and reactivate the function if necessary using a dedicated setting.&#x20;

A method is available in `DriveKitTripAnalysis` to enable or disable the feature:

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

```swift
func activateCrashDetection(_ enable: Bool)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The crash detection comes with an optional user interface to display an alert to the driver. This is described in the [user interface](https://docs.drivequant.com/trip-analysis/user-interface/ios/driver-alert-in-case-of-crash) section.
{% endhint %}

## Verify that the feature is available

It is possible to check if the crash detection is available for your configuration by checking the following property:

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

```swift
var isCrashDetectionAvailable: Bool
```

{% endtab %}
{% endtabs %}

This property returns `true` if:

* the required smartphone sensors are available and up and running;
* your API key is allowed to use the feature;

{% hint style="info" %}
If this property returns `false`, DriveKit will not start crash detection feature even if it has been previously activated with `activateCrashDetection()`.
{% endhint %}

## Configure crash detection feedback

Trip Analysis offers a mechanism to ask the user for feedback when an accident is confirmed by the crash analysis service. Crash confirmation can be used to trigger a notification or display a screen which asks the driver to confirm the accident and whether assistance is required.

To use this function, you simply need to enable the interface with the following method and a [`DKCrashFeedbackConfig`](https://docs.drivequant.com/trip-analysis/ios/references#dkcrashfeedbackconfig) object:

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

```swift
func enableCrashFeedback(config: DKCrashFeedbackConfig)
```

{% endtab %}
{% endtabs %}

To disable the crash detection feedback, call the following method:

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

```swift
func disableCrashFeedback()
```

{% endtab %}
{% endtabs %}

## Listening to Crash events

TripListener protocol provides two callbacks for crash events:

* `crashDetected(crashInfo:`[`DKCrashInfo`](https://docs.drivequant.com/trip-analysis/ios/references#dkcrashinfo)`)`, called when a crash event is detected
* `crashFeedbackSent(crashInfo:`[`DKCrashInfo`](https://docs.drivequant.com/trip-analysis/ios/references#dkcrashinfo)`, feedbackType:` [`DKCrashFeedbackType`](https://docs.drivequant.com/trip-analysis/ios/references#crashfeedbacktype)`, severity:`[`DKCrashFeedbackSeverity`](https://docs.drivequant.com/trip-analysis/ios/references#crashfeedbackseverity)`)`, called when crash feedback is enabled and a confirmed crash is detected. This callback will contain crash information and the feedback from the user.

To receive these callbacks, the smartphone must be connected to a mobile network and the accident detection feature must be enabled for your organisation's API key.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.drivequant.com/trip-analysis/ios/crash-detection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
