Skip to content

Read your first health data in C++

Use FHealthBridgeService to initialize the active provider and read step samples. All completion callbacks run on the game thread.

#include "HealthBridgeService.h"
#include "HealthBridgeTypes.h"
void ReadRecentSteps()
{
FHealthBridgeService::AutoInitialize([](bool bReady)
{
if (!bReady || !FHealthBridgeService::IsReady())
{
UE_LOG(LogTemp, Warning, TEXT("HealthBridge is not ready"));
return;
}
const FHealthDataQuery Query(TEXT("steps"), 7, 100);
FHealthBridgeService::ReadData(
Query,
[](const FHealthDataReadResult& Result)
{
if (!Result.bSuccess)
{
UE_LOG(LogTemp, Warning, TEXT("HealthBridge read failed: %s"),
*Result.Error);
return;
}
for (const FHealthDataSample& Sample : Result.Samples)
{
const double Count = Sample.GetNumber(TEXT("count"));
UE_LOG(LogTemp, Log, TEXT("Step sample: %.0f"), Count);
}
});
});
}

FHealthDataQuery clamps DaysBack to 1–90 and MaxRecords to at least 1.

bSuccess=true with an empty Samples array is a valid outcome. It can mean:

  • The selected period contains no records.
  • The device has not synchronized yet.
  • On iOS, the player declined read access without exposing that decision to the app.

Do not turn an empty read into a hard error or claim that the player has no health data.

Run the project in the editor. The expected result is:

  • Initialization succeeds against provider Mock.
  • The read result succeeds.
  • At least one generated step count appears in the Output Log.

Remove or sanitize sample logging before shipping. Health samples and record IDs must not enter general telemetry or support logs.