Class SensorSessionOptions
SensorSession should behave: reconnection, where samples go,
and how stale a cached reading may be.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionHow old a sample may be before it is dropped, as a Duration.intThe staleness threshold in milliseconds.How long samples are batched before a store write, as a Duration.intThe store write-batch interval in milliseconds.The attached workout, or null.booleantruewhen the session reconnects automatically.booleantruewhen samples are written through to the health store.setAutoReconnect(boolean autoReconnect) setStaleSample(Duration value) How old a sample may be before it is dropped.setStaleSampleMillis(int staleSampleMillis) setStoreBatch(Duration value) How long samples are batched before a store write.setStoreBatchMillis(int storeBatchMillis) setWorkoutSession(WorkoutSession workoutSession) Attaches this sensor to a workout, so its samples become part of that workout's statistics and are persisted with it.setWriteToStore(boolean writeToStore) Whether received samples are written through to the platform health store.
-
Constructor Details
-
SensorSessionOptions
public SensorSessionOptions()
-
-
Method Details
-
setAutoReconnect
-
isAutoReconnect
public boolean isAutoReconnect()truewhen the session reconnects automatically. -
setWriteToStore
Whether received samples are written through to the platform health store. Defaults to
false, and that default is deliberate.During a workout on watchOS -- and on iOS 26 and later -- the operating system records heart rate into HealthKit itself. A strap that also writes its own heart-rate samples then produces two overlapping sets for the same minutes, and every downstream average, maximum and chart is computed over double-counted data.
This release drives no live workout session, so that overlap comes from a workout the user started elsewhere -- in Apple's own Workout app, say -- rather than from one of yours. The default stays
falseregardless: turning it on is a decision about somebody else's data as much as your own.If you are recording a workout, attach the session to it with
setWorkoutSession(WorkoutSession)instead: samples land in the workout's statistics and are persisted once, as part of the workout, when it ends.Turning this on is right when you are logging a standalone measurement the OS knows nothing about -- a weight from a scale, a body temperature from a thermometer, a glucose reading from a meter.
Blood pressure is not among them on mobile in this release. It is two values in one reading, which HealthKit models as a correlation and Health Connect as its own record type, and neither is implemented here -- the sample line this API writes over carries a single value. A cuff reading routed to the store therefore fails with HealthError#TYPE_NOT_SUPPORTED on both platforms rather than being quietly dropped, and the local and simulator stores keep it fine. Read it off the session and persist it yourself until the correlation paths land.
-
isWriteToStore
public boolean isWriteToStore()truewhen samples are written through to the health store. -
setStoreBatch
How long samples are batched before a store write.
The Duration form of
setStoreBatchMillis(int), which is the type the rest of the framework speaks; the millis form stays for the ports and the wire format. -
getStoreBatch
-
setStoreBatchMillis
-
getStoreBatchMillis
public int getStoreBatchMillis()The store write-batch interval in milliseconds. -
setWorkoutSession
Attaches this sensor to a workout, so its samples become part of that workout's statistics and are persisted with it.
This is the right way to feed a heart-rate strap into a recorded workout -- see the warning on
setWriteToStore(boolean). -
getWorkoutSession
The attached workout, or null. -
setStaleSample
How old a sample may be before it is dropped.
The Duration form of
setStaleSampleMillis(int), which is the type the rest of the framework speaks; the millis form stays for the ports and the wire format. -
getStaleSample
-
setStaleSampleMillis
-
getStaleSampleMillis
public int getStaleSampleMillis()The staleness threshold in milliseconds.
-