Documentation Index Fetch the complete documentation index at: https://mintlify.com/kingstinct/react-native-healthkit/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Heartbeat series data contains individual heartbeat timing information, including whether each heartbeat was preceded by a gap in data collection. This data is typically captured during workouts or ECG recordings.
Functions
queryHeartbeatSeriesSamples
Query heartbeat series samples from HealthKit.
import { HeartbeatSeries } from '@kingstinct/react-native-healthkit/modules' ;
const samples = await HeartbeatSeries . queryHeartbeatSeriesSamples ({
limit: 20 ,
ascending: false ,
});
Parameters
options
QueryOptionsWithSortOrder
Query options for heartbeat series samples Maximum number of samples to return
Filter options for date range and other criteria
Response
Returns a Promise resolving to an array of HeartbeatSeriesSample objects.
interface HeartbeatSeriesSample {
readonly uuid : string ;
readonly startDate : Date ;
readonly endDate : Date ;
readonly heartbeats : readonly Heartbeat [];
}
interface Heartbeat {
readonly timeSinceSeriesStart : number ; // seconds
readonly precededByGap : boolean ;
}
queryHeartbeatSeriesSamplesWithAnchor
Query heartbeat series samples with anchor-based pagination for efficient syncing.
import { HeartbeatSeries } from '@kingstinct/react-native-healthkit/modules' ;
// Initial query
const { samples , deletedSamples , newAnchor } =
await HeartbeatSeries . queryHeartbeatSeriesSamplesWithAnchor ({
limit: 20 ,
});
// Next page
const nextResult = await HeartbeatSeries . queryHeartbeatSeriesSamplesWithAnchor ({
anchor: newAnchor ,
limit: 20 ,
});
Parameters
Query options with anchor support Maximum number of samples to return. Set to 0 for no limit.
Base64-encoded anchor from previous query. Omit for initial query.
Filter options for date range and other criteria
Response
interface HeartbeatSeriesSamplesWithAnchorResponse {
readonly samples : readonly HeartbeatSeriesSample [];
readonly deletedSamples : readonly DeletedSample [];
readonly newAnchor : string ;
}
New or modified heartbeat series samples since the last anchor
Samples that were deleted since the last anchor
Base64-encoded anchor to use for the next query
Usage Example
import { HeartbeatSeries } from '@kingstinct/react-native-healthkit/modules' ;
import { requestAuthorization } from '@kingstinct/react-native-healthkit' ;
// Request authorization first
await requestAuthorization ({
toRead: [ 'HKDataTypeIdentifierHeartbeatSeries' ]
});
// Query heartbeat series
const samples = await HeartbeatSeries . queryHeartbeatSeriesSamples ({
limit: 20 ,
ascending: false ,
});
samples . forEach (( sample ) => {
console . log ( `Series with ${ sample . heartbeats . length } heartbeats` );
console . log ( `Duration: ${ sample . endDate . getTime () - sample . startDate . getTime () } ms` );
sample . heartbeats . forEach (( beat , index ) => {
console . log (
`Beat ${ index + 1 } : ${ beat . timeSinceSeriesStart } s` +
( beat . precededByGap ? ' (gap before)' : '' )
);
});
});
import { HeartbeatSeries } from '@kingstinct/react-native-healthkit/modules' ;
let anchor : string | undefined ;
let allSamples : HeartbeatSeriesSample [] = [];
// Fetch all pages
do {
const { samples , newAnchor } =
await HeartbeatSeries . queryHeartbeatSeriesSamplesWithAnchor ({
anchor ,
limit: 100 ,
});
allSamples = [ ... allSamples , ... samples ];
anchor = samples . length > 0 ? newAnchor : undefined ;
} while ( anchor );
console . log ( `Total heartbeat series: ${ allSamples . length } ` );
See Also