I am developing an app to calculate the Heart rate using SwiftUI. Code is measuring hear rate accurately. But when I took my watch off form my wrist it still showing the heart rate. I have check the apple heart rate app which stop showing the HR as I took of my watch form wrist.
swift
let healthKitTypes: Set = [ HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)!]
healthStore.requestAuthorization(toShare: healthKitTypes, read: healthKitTypes) { _, _ in }
let devicePredicate = HKQuery.predicateForObjects(from: [HKDevice.local()])
let updateHandler: (HKAnchoredObjectQuery, [HKSample]?, [HKDeletedObject]?, HKQueryAnchor?, Error?) - Void = { query, samples, deletedObjects, queryAnchor, error in
guard let samples = samples as? [HKQuantitySample] else { return } self.process(samples, type: quantityTypeIdentifier)
}
let query = HKAnchoredObjectQuery(type: HKObjectType.quantityType(forIdentifier: quantityTypeIdentifier)!, predicate: devicePredicate, anchor: nil, limit: HKObjectQueryNoLimit, resultsHandler: updateHandler) query.updateHandler = updateHandler
healthStore.execute(query)
How Can I achieve this in my application.
Post
Replies
Boosts
Views
Activity
I am developing an watchOS app the need to continuously send current Heart Rate to server. To run the app continuously in background I have to start HKWorkoutSession but this open our app each even I kill the app. How can I do it correctly.