syncSteps

abstract suspend fun syncSteps(): AFResult

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

This is the primary sync entry point. It orchestrates the complete flow:

  1. Checks that a member ID and device type are available.

  2. For HealthKit/Health Connect devices: calls getDatesToSync, reads data from the device health store for those dates, and calls submitActivities.

  3. For legacy Android/Fitbit devices: triggers a server-side sync via API.

  4. On success, records the current timestamp as smartWalkingLastSyncTimestamp.

Concurrency guard: If a sync is already in progress, returns immediately with AFResult(false, "Sync already in progress"). Only one sync runs at a time.

Sync state: Emits SmartWalkingEvent.SyncStarted at the start, SmartWalkingEvent.SyncCompleted on success, or SmartWalkingEvent.SyncFailed on failure via syncEvents.

Kotlin

lifecycleScope.launch {
val result = AFCore.smartWalking().syncSteps()
if (result.status) {
showMessage("Sync complete")
} else {
showMessage("Sync skipped: ${result.statusMessage}")
}
}

Swift

Task {
let result = try await AFCore.shared.smartWalking().syncSteps()
if result.status {
showMessage("Sync complete")
} else {
showMessage("Sync skipped: \(result.statusMessage ?? "")")
}
}

Return

AFResult — check status for success.