SmartWalking

interface SmartWalking

SmartWalking — health device connection and step-data synchronization.

SmartWalking bridges external health platforms (Apple HealthKit, Google Health Connect) with the member’s ActiveFit profile. It reads steps, calories, distance, and duration from the device’s health store and submits them to the backend.

Setup Flow (Consumer App)

Each platform has a single "connect" entry point that handles registration and health-permission prompts in one call:

PlatformMethodHealth Store
iOS / watchOSconnectAppleHealthKitApple HealthKit
AndroidconnectGoogleHealthConnectGoogle Health Connect

After a successful connection, auto-sync is enabled automatically. The SDK will periodically sync step data in the background (approximately hourly).

Sync Lifecycle

  1. The backend maintains a list of dates that need syncing (getDatesToSync).

  2. The SDK reads health data for those dates from the device health store.

  3. The SDK posts the data to the backend (submitActivities).

  4. syncSteps orchestrates this entire flow in one call.

With auto-sync enabled (enableAutoSync), this happens automatically via:

  • iOS/watchOS: HealthKit background delivery observer (fires when new step data arrives)

  • Android: WorkManager periodic task (hourly, requires network + battery not low)

Observability

Disconnection

Call unregisterUser to disconnect. This disables auto-sync, tells the server the member is no longer configured, and clears all local SmartWalking state. The member’s historical data on the server is preserved.

Error Handling

  • Network errors propagate as exceptions. Wrap calls in try/catch (Kotlin) or do/catch (Swift).

  • syncSteps and submitActivities return AFResult with status = false for non-exception failures (e.g. "no dates to sync", "no activities to submit"). Check AFResult.status before treating the operation as successful.

  • If a sync is already in progress, syncSteps returns immediately with AFResult(false, "Sync already in progress") — it does not queue.

Prerequisites

  • The health platform app must be installed on the device:

  • iOS: Apple Health (built-in)

  • Android: Google Health Connect (may need to be installed from Play Store)

  • The member must be authenticated (AFCore.isLoggedIn() == true).

  • The member must have the "smartwalking" program entitlement (checked during auto-restore).

Properties

Link copied to clipboard

Whether automatic background sync is currently enabled.

Link copied to clipboard
open val syncEvents: StateFlow<SmartWalkingEvent>

Observable SmartWalking event state.

Functions

Link copied to clipboard
abstract suspend fun connectAppleHealthKit(deviceId: String): SmartWalkingProfile

iOS primary setup flow — requests HealthKit permissions and registers the device.

Link copied to clipboard
abstract suspend fun connectGoogleHealthConnect(context: Any, deviceId: String): SmartWalkingProfile

Android primary setup flow — requests Health Connect permissions and registers the device.

Link copied to clipboard
abstract suspend fun disableAutoSync()

Disables automatic background step synchronization.

Link copied to clipboard
abstract suspend fun enableAutoSync()

Enables automatic background step synchronization.

Link copied to clipboard
abstract suspend fun getDailyStepGoal(): Int

Fetches the member’s daily step goal from the "smartwalking" program entitlement.

Link copied to clipboard
abstract suspend fun getDatesToSync(): List<LocalDate>

Asks the server which dates still need health data.

Link copied to clipboard
abstract suspend fun getDiagnostics(): SmartWalkingDiagnostics

Returns a comprehensive diagnostic snapshot of SmartWalking state.

Link copied to clipboard
abstract suspend fun getRegisteredProfile(): SmartWalkingProfile?

Fetches the member’s current SmartWalking profile from the server.

Link copied to clipboard

Returns the apps and devices that have contributed step-count data to HealthKit.

Link copied to clipboard
abstract suspend fun registerUser(deviceId: String, deviceType: DeviceType): SmartWalkingProfile

Registers (or re-registers) the member with SmartWalking for a specific device.

Link copied to clipboard
abstract suspend fun submitActivities(activities: List<HealthData>): AFResult

Submits a batch of health data entries to the backend.

Link copied to clipboard
abstract fun subscribeToEvents(onEvent: (SmartWalkingEvent) -> Unit, onError: (Throwable) -> Unit = {}): FlowSubscription

Subscribes to SmartWalking lifecycle events (sync progress, permission changes, background delivery triggers).

Link copied to clipboard
abstract suspend fun syncSteps(): AFResult

Full sync cycle: fetches dates to sync, reads health data, and submits it.

Link copied to clipboard
abstract suspend fun unregisterUser(): Boolean

Disconnects the member from SmartWalking.