Smart Walking
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:
| Platform | Method | Health Store |
|---|---|---|
| iOS / watchOS | connectAppleHealthKit | Apple HealthKit |
| Android | connectGoogleHealthConnect | Google 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
The backend maintains a list of dates that need syncing (getDatesToSync).
The SDK reads health data for those dates from the device health store.
The SDK posts the data to the backend (submitActivities).
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
syncEvents — observe whether a sync is in progress (SmartWalkingEvent.SyncStarted) or idle. Useful for showing a sync indicator in the UI.
isAutoSyncEnabled — whether background sync is active.
getDiagnostics — a full snapshot for debugging (profile, permissions, data sources, last sync timestamp).
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) ordo/catch(Swift).syncSteps and submitActivities return AFResult with
status = falsefor non-exception failures (e.g. "no dates to sync", "no activities to submit"). CheckAFResult.statusbefore 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
Functions
iOS primary setup flow — requests HealthKit permissions and registers the device.
Android primary setup flow — requests Health Connect permissions and registers the device.
Disables automatic background step synchronization.
Enables automatic background step synchronization.
Fetches the member’s daily step goal from the "smartwalking" program entitlement.
Asks the server which dates still need health data.
Returns a comprehensive diagnostic snapshot of SmartWalking state.
Fetches the member’s current SmartWalking profile from the server.
Returns the apps and devices that have contributed step-count data to HealthKit.
Registers (or re-registers) the member with SmartWalking for a specific device.
Submits a batch of health data entries to the backend.
Subscribes to SmartWalking lifecycle events (sync progress, permission changes, background delivery triggers).
Disconnects the member from SmartWalking.