> ## 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.

# React Native Health SDK Troubleshooting

> Fix React Native SDK issues: HealthKit permissions not showing, Health Connect unavailable, and background sync failures. Covers Expo and bare workflow.

## Common Issues

> [accordion] HealthKit permissions not showing (iOS)
>
> **Symptoms:** The health permissions dialog doesn't appear when calling `requestAuthorization()`.
>
> **Solutions:**
>
> 1. **Verify Info.plist configuration:**
>    ```xml theme={null}
>    <key>NSHealthShareUsageDescription</key>
>    <string>This app syncs your health data to your account.</string>
>    ```
>
> 2. **Check HealthKit capability in Xcode:**
>    * Open `ios/[ProjectName].xcworkspace`
>    * Select target → Signing & Capabilities
>    * Ensure HealthKit is listed
>
> 3. **Run on physical device:**
>    HealthKit doesn't work in the iOS Simulator. Always test on a real device.
>
> 4. **Check provisioning profile:**
>    Your Apple Developer account must have HealthKit capability enabled for the App ID.

> [accordion] Health Connect permissions not showing (Android)
>
> **Symptoms:** Permission dialog doesn't appear on Android.
>
> **Solutions:**
>
> 1. **Ensure Health Connect is installed:**
>    Health Connect must be installed on the device. It's pre-installed on Android 14+ but may need to be installed from Play Store on older versions.
>
> 2. **Set provider before requesting authorization:**
>    ```ts theme={null}
>    OpenWearablesHealthSDK.setProvider("google"); // or "samsung"
>    const authorized = await OpenWearablesHealthSDK.requestAuthorization([
>       HealthDataType.Steps,
>       HealthDataType.HeartRate,
>       HealthDataType.Sleep
>    ]);
>    // Android: true only if every requested permission was granted.
>    // A partial grant returns false, but the granted types still sync.
>    console.log("All permissions granted:", authorized);
>    ```
>
> 3. **Check minSdk version:**
>    Your `android/app/build.gradle` must have `minSdk 29` or higher.
>
> 4. **Verify the Activity is set (if using native Android directly):**
>    The React Native plugin handles this automatically, but if you see permission launcher issues, try rebuilding the app.

> [accordion] Background sync not working (iOS)
>
> **Symptoms:** Data only syncs when the app is in the foreground.
>
> **Solutions:**
>
> 1. **Verify background modes in Info.plist:**
>    ```xml theme={null}
>    <key>UIBackgroundModes</key>
>    <array>
>        <string>fetch</string>
>        <string>processing</string>
>    </array>
>
>    <key>BGTaskSchedulerPermittedIdentifiers</key>
>    <array>
>        <string>com.openwearables.healthsdk.task.refresh</string>
>        <string>com.openwearables.healthsdk.task.process</string>
>    </array>
>    ```
>
> 2. **Check Background App Refresh setting:**
>    * Go to iOS Settings → Your App → Background App Refresh
>    * Ensure it's enabled
>
> 3. **Check Low Power Mode:**
>    Background tasks are suspended when Low Power Mode is active.
>
> 4. **Wait for system scheduling:**
>    iOS controls when background tasks run. Initial syncs may take 15+ minutes to trigger.

> [accordion] Background sync not working (Android)
>
> **Symptoms:** Data only syncs when the app is in the foreground on Android.
>
> **Solutions:**
>
> 1. **Check battery optimization:**
>    Some Android manufacturers aggressively kill background services. Ask users to disable battery optimization for your app in Settings.
>
> 2. **Verify notification permissions:**
>    On Android 13+, the SDK uses a foreground service notification during sync. Ensure `POST_NOTIFICATIONS` permission is granted.
>
> 3. **Check provider connection:**
>    Verify the health provider is properly connected:
>    ```ts theme={null}
>    const providers = OpenWearablesHealthSDK.getAvailableProviders();
>    console.log(providers);
>    ```

> [accordion] Sync doesn't start
>
> **Symptoms:** `startBackgroundSync()` resolves `false`. It never throws - check the return value.
>
> **Solutions:**
>
> 1. **Call `configure()` on every app launch**, before any other SDK call.
> 2. **Check that a user is signed in** - `isSessionValid()` must be `true`.
> 3. **iOS: request authorization first.** Sync won't start without at least one authorized type.
> 4. **Listen for auth errors.** `signIn()` doesn't validate the tokens - an invalid token shows up later as an `onAuthError` event during sync:
>    ```ts theme={null}
>    OpenWearablesHealthSDK.addListener("onAuthError", ({ statusCode, message }) => {
>      console.error(`Auth error ${statusCode}: ${message}`);
>    });
>    ```

> [accordion] Data not appearing in Open Wearables
>
> **Symptoms:** Sync completes but data doesn't show up in the API.
>
> **Solutions:**
>
> 1. **Check sync status:**
>    ```ts theme={null}
>    const status = OpenWearablesHealthSDK.getSyncStatus();
>    console.log("Sent count:", status.sentCount);
>    ```
>
> 2. **Verify health data exists:**
>    Open Apple Health or Health Connect and confirm data exists for the requested types.
>
> 3. **Check date range:**
>    The SDK syncs data incrementally. New data may not exist yet.
>
> 4. **Reset anchors for a full re-sync** (while sync is stopped):
>    ```ts theme={null}
>    await OpenWearablesHealthSDK.stopBackgroundSync();
>    OpenWearablesHealthSDK.resetAnchors();
>    await OpenWearablesHealthSDK.startBackgroundSync(90);
>    ```
>
> 5. **Check permissions:**
>    Users may have denied specific data types even if they approved the overall request.

> [accordion] Samsung Health not available
>
> **Symptoms:** The `samsung` entry from `getAvailableProviders()` has `isAvailable: false`, or `setProvider("samsung")` returns `false`.
>
> **Solutions:**
>
> 1. **Samsung Health must be installed** on the device.
> 2. **Samsung devices only** - Samsung Health is typically only available on Samsung devices.
> 3. **Try Health Connect instead** as it works on all Android 10+ devices:
>    ```ts theme={null}
>    OpenWearablesHealthSDK.setProvider("google");
>    ```

## HealthKit Entitlement Issues (iOS)

If you see "Missing HealthKit entitlement" errors:

1. **In Xcode:**
   * Target → Signing & Capabilities → Add HealthKit
   * Check "Background Delivery" for background updates

2. **In Apple Developer Portal:**
   * App IDs → Your App → Capabilities
   * Enable HealthKit

3. **Regenerate provisioning profiles** after making changes

### Background Delivery Limitations (iOS)

iOS has strict limits on background execution:

| Factor | Impact |
| - | - |
| Battery Level | Background tasks paused below 20% |
| Low Power Mode | All background tasks suspended |
| User Behavior | iOS learns when you use the app and schedules accordingly |
| Network | Background tasks require network connectivity |

> [!TIP]
>
> There is no manual sync call. If data is urgent, ask users to open the app - the SDK resumes an interrupted sync when the app comes to the foreground.

## Testing Background Sync

### iOS

To test background sync during development:

1. Run app on device
2. Navigate to home screen
3. Wait 15+ minutes (or use Xcode's debug menu)
4. Check logs for sync activity

In Xcode, you can simulate background fetch:

* Debug → Simulate Background Fetch

### Android

1. Run app on device or emulator
2. Minimize the app
3. The SDK uses WorkManager which should trigger relatively quickly
4. Check logs via the `onLog` event listener

## Debugging Tips

### Enable Debug Logging

```ts theme={null}
import OpenWearablesHealthSDK from "open-wearables";

// Listen to SDK logs
const logSub = OpenWearablesHealthSDK.addListener("onLog", ({ message }) => {
  console.log("[HealthSDK]", message);
});

// Listen to auth errors
const authSub = OpenWearablesHealthSDK.addListener("onAuthError", ({ statusCode, message }) => {
  console.error(`[HealthSDK] Auth error: ${statusCode} - ${message}`);
});

// Log current state
console.log("Is session valid:", OpenWearablesHealthSDK.isSessionValid());
console.log("Is sync active:", OpenWearablesHealthSDK.isSyncActive());
console.log("Stored credentials:", OpenWearablesHealthSDK.getStoredCredentials());

// Clean up when done
logSub.remove();
authSub.remove();
```

### Check Stored Credentials

```ts theme={null}
const creds = OpenWearablesHealthSDK.getStoredCredentials();
console.log("Stored credentials:", creds);
```

### Monitor Sync Progress

```ts theme={null}
const status = OpenWearablesHealthSDK.getSyncStatus();
console.log("Has resumable session:", status.hasResumableSession);
console.log("Sent count:", status.sentCount);
console.log("Is full export:", status.isFullExport);
console.log("Created at:", status.createdAt);
```

### Force Fresh Start

If things are in a bad state:

```ts theme={null}
// Clears credentials, anchors and the sync session
await OpenWearablesHealthSDK.stopBackgroundSync();
OpenWearablesHealthSDK.signOut();

// Then sign in again - the next sync re-uploads history within syncDaysBack
await OpenWearablesHealthSDK.signIn(userId, accessToken, refreshToken, null);
await OpenWearablesHealthSDK.startBackgroundSync(90);
```

## Getting Help

If you're still experiencing issues:

> [card] [GitHub Issues](https://github.com/the-momentum/open-wearables-react-native-sdk/issues)
>
> Report bugs or request features on the SDK repository.

> [card] [Discussions](https://github.com/the-momentum/open-wearables/discussions)
>
> Ask questions and get help from the community.

When reporting issues, please include:

* React Native version (`npx react-native --version`)
* SDK version (from `package.json`)
* Platform (iOS/Android) and OS version
* Device model
* Relevant logs and error messages
* Steps to reproduce


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