> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/faq/help-topics/data-api-sdk/realtime-streaming-and-ble/realtime-keep-alive-backgrounded-ios.md).

# How do I keep BLE streaming alive when iOS is backgrounded?

**Continuous websocket realtime streaming cannot run while the iOS app is backgrounded.** iOS suspends backgrounded apps unless they use a permitted background mode, and a websocket stream isn't among them (`beginBackgroundTask` only buys limited time).

**The BLE connection to the device can persist, though.** In Xcode:

{% stepper %}
{% step %}
Add **Background Modes**.
{% endstep %}

{% step %}
Tick **'Uses Bluetooth LE Accessories'**.
{% endstep %}
{% endstepper %}

Without this, iOS suspends BLE updates shortly after the app leaves the foreground.

The app can then keep receiving sensor data over BLE in the background and **periodically dispatch webhook events to your backend**, instead of maintaining the websocket stream.

See [Terra to your backend](https://docs.tryterra.co/streaming-api/terra-greater-than-your-backend) for the webhook-based streaming pattern.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.tryterra.co/faq/help-topics/data-api-sdk/realtime-streaming-and-ble/realtime-keep-alive-backgrounded-ios.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.
