> ## Documentation Index
> Fetch the complete documentation index at: https://openwearables.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Open Wearables Mobile SDK

> Native mobile SDKs for background sync from Apple HealthKit, Samsung Health, and Health Connect. iOS, Android, Flutter, and React Native supported.

## Introduction

Open Wearables Mobile SDKs enable seamless background synchronization of health data directly from **Apple HealthKit** (iOS), **Samsung Health**, and **Health Connect** (Android) to the Open Wearables platform.

Unlike cloud-based providers (Garmin, Polar, Suunto) that use webhooks and OAuth, on-device health stores require a **push-based model** where data is sent from the user's device to your backend.

> [!NOTE]
>
> **Why Push-Based?** Apple HealthKit, Samsung Health, and Health Connect don't expose cloud APIs. Health data lives exclusively on the user's device, so the mobile app must actively push data to your backend.

## Architecture Overview

**1. Health Data Store**

Health data is stored locally on the user's device — in Apple Health (iOS), Samsung Health, or Health Connect (Android).

**2. Your App + Mobile SDK**

The SDK reads data from the health store and handles background synchronization automatically. Available as native iOS (Swift), native Android (Kotlin), Flutter, or React Native.

**3. Open Wearables Platform**

Data is pushed to `POST {host}/api/v1/sdk/users/{userId}/sync` and normalized to the unified data model.

The [Integration Guide](https://openwearables.io/docs/sdk/integration.md) walks through the flow step by step, the same for every SDK.

## Key Features

> [card] Background Sync
>
> Health data syncs automatically even when your app is in the background, using iOS Background App Refresh or Android WorkManager.

> [card] Incremental Updates
>
> Uses anchored queries to sync only new data since the last sync, minimizing battery usage and network traffic.

> [card] Secure Storage
>
> Credentials stored securely in iOS Keychain or Android EncryptedSharedPreferences. API keys never leave your backend.

> [card] Wide Data Support
>
> Steps, heart rate, workouts, sleep, body measurements, nutrition, and more — all normalized to Open Wearables data model.

## Available SDKs

> [card] [iOS (Swift)](https://openwearables.io/docs/sdk/ios.md)
>
> Native iOS SDK — the core implementation for Apple HealthKit sync.

> [card] [Android (Kotlin)](https://openwearables.io/docs/sdk/android.md)
>
> Native Android SDK — sync from Samsung Health and Health Connect.

> [card] [Flutter](https://openwearables.io/docs/sdk/flutter.md)
>
> Flutter SDK — cross-platform wrapper around the native iOS and Android SDKs.

> [card] [React Native](https://openwearables.io/docs/sdk/react-native.md)
>
> React Native SDK — cross-platform wrapper around the native iOS and Android SDKs.

## Choosing an onboarding flow

For any real integration, use the **backend token flow**: your backend mints a short-lived, user-scoped token (write-only to the `/sdk/*` endpoints) via [`POST /api/v1/users/{user_id}/token`](https://openwearables.io/docs/api-reference/external:-mobile-sdk/create-user-token) and forwards it to the app over its own authenticated API. Your `app_secret` never touches the device. This is the standard path, covered in the [Integration Guide](https://openwearables.io/docs/sdk/integration.md).

> [!WARNING]
>
> **Invitation codes are a niche mechanism, not a co-equal second option.** They exist for apps with **no backend of their own** to mint and forward tokens. Right now the flow is aimed primarily at individual users self-hosting Open Wearables for their own data (and the [Open Wearables app](https://openwearables.io/docs/app/introduction.md) / quick manual testing), not at multi-user production integrations. If you are building your own app with its own backend, use the backend token flow above.

With an invitation code, a single-use code is issued via [`POST /api/v1/users/{user_id}/invitation-code`](https://openwearables.io/docs/api-reference/external:-mobile-sdk/generate-invitation-code) - from the dashboard or the API - and the app redeems it directly against the public [`POST /api/v1/invitation-code/redeem`](https://openwearables.io/docs/api-reference/external:-mobile-sdk/redeem-invitation-code) to obtain SDK tokens. Two situations are possible: in the primary case the same person generates the code in their own dashboard and enters it in their own app, so it never leaves that person. A code can also be delegated - for example a coach or clinician issuing one for a client - and **only in that hand-off** does the code travel to someone else; when it does, use a **secure channel**, because the code is the sole credential (single-use blocks replay after redemption, but not first-use theft if the code is intercepted in transit).

## Security Model

The SDK uses a secure token-based authentication flow that keeps your App credentials safe:

1. **App credentials stay on your backend** - `app_id` and `app_secret` are never exposed to mobile apps
2. **Short-lived access tokens** - In the standard backend token flow, generated server-to-server via `POST /api/v1/users/{user_id}/token` and forwarded to the mobile SDK. With the invitation code flow, the app instead redeems a single-use code at `POST /api/v1/invitation-code/redeem` and receives the tokens directly.
3. **Secure credential storage** - iOS Keychain / Android EncryptedSharedPreferences
4. **Automatic token refresh** - SDK can automatically refresh expired tokens using the `refresh_token`
5. **API key auth** - Alternative for internal tools (not recommended for production)

> [!WARNING]
>
> **Never embed your `app_id` / `app_secret` in your mobile app.** Always generate access tokens on your backend and pass only the tokens to the mobile SDK.

## Disconnecting

In most SDKs `signOut()` only clears the credentials stored on the device. It makes no network call, so on its own the backend never learns the user left: the connection stays `active` behind a plausible `last_synced_at` and is indistinguishable from a healthy one. The native iOS SDK reports the disconnect itself from version 0.15.0; the other SDKs need the call below.

To report the disconnect, call [`DELETE /api/v1/users/{user_id}/connections/{provider}`](https://openwearables.io/docs/api-reference/external:-connections/disconnect-provider-endpoint) with the SDK access token **before** signing out locally:

```bash theme={null}
curl -X DELETE "https://api.openwearables.io/api/v1/users/$USER_ID/connections/apple" \
  -H "Authorization: Bearer $SDK_ACCESS_TOKEN"
```

A `204` means the connection is revoked. The endpoint is idempotent, so a retry after a failed sign-out is safe, and a `404` means there was no connection to revoke.

An SDK token is deliberately narrower here than a developer JWT or an API key:

| Rule | Response when violated |
| - | - |
| The token's user must be the `user_id` in the path | `403` |
| The provider must be one that can be fed by the SDK (Apple Health, Health Connect, Samsung Health) | `403` |
| The connection must not hold OAuth tokens - cloud connections such as Google Health are out of the app's reach | `403` |

No provider deregistration runs on this path: signing out of an app is not a reason to unregister the user from the provider's API. The resulting `connection.revoked` webhook carries `reason: "sdk_sign_out"`, which distinguishes it from a disconnect made in the dashboard.

> [!NOTE]
>
> Revoking permissions in the iOS Settings app and deleting the app cannot be reported - the SDK never runs again to make the call. Treat a connection that stops uploading as a separate signal from one that was explicitly revoked.

## Next Steps

> [card] [iOS SDK](https://openwearables.io/docs/sdk/ios.md)
>
> Get started with the native iOS SDK (Swift)

> [card] [Android SDK](https://openwearables.io/docs/sdk/android.md)
>
> Get started with the native Android SDK (Kotlin)

> [card] [Flutter SDK](https://openwearables.io/docs/sdk/flutter.md)
>
> Get started with the Flutter SDK

> [card] [React Native SDK](https://openwearables.io/docs/sdk/react-native.md)
>
> Get started with the React Native SDK


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.