Our Hubro Connect library for iOS integrates with HealthKit. This integration facilitates the collection of data from HealthKit and the transfer of this data to the backend storage.
<key>NSHealthShareUsageDescription</key>
<string>$(PRODUCT_NAME) would like to access your HealthKit data to provide personalized insights and recommendations.
</string>
<key>NSHealthUpdateUsageDescription</key>
<string>$(PRODUCT_NAME) would like to record your health data to provide advanced health monitoring and analysis.
</string>
Once the initial setup is finished, you can implement the authorization process to HealthKit. During this step you need to provide all record types you would like to access once the authorization is finished.
For background data processing, this implementation relies on iOS's Background Fetch mechanism. Background Fetch allows the app to periodically wake up to fetch and process data in the background, even when the app is not actively being used. This ensures that the health data is continuously synchronized with the backend without requiring user intervention.
Once done, you can activate the data collection to the server using
import hubro_connect
//..
// Initialize the user session (let the user log in)
// Let's suppose that 'session' variable holds valid session
//..
ManagerFactory().createDataSyncManager(hubroSession: session, types: [HealthDataTypeSteps])
try? await manager?.startCollection(interval: nil)