tomar ritmo pulsometro puede presion para normal medir medidor frecuencia con cardiaco cardiaca arterial app ios watchkit apple-watch watch-os

ios - pulsometro - Ver OS 2.0 beta: acceso a ritmo cardíaco



ritmo cardiaco normal (4)

Con Watch OS 2.0, se supone que los desarrolladores pueden acceder a los sensores de latidos cardíacos ... Me encantaría jugar un poco con él y construir un prototipo simple para una idea que tengo, pero no puedo encontrar información ni documentación en ningún lugar Esta característica.

¿Alguien puede indicarme cómo abordar esta tarea? Cualquier enlace o información sería apreciada.


Apple no está técnicamente dando a los desarrolladores acceso a los sensores de ritmo cardíaco en watchOS 2.0. Lo que están haciendo es proporcionar acceso directo a los datos de frecuencia cardíaca registrados por el sensor en HealthKit. Para hacer esto y obtener datos casi en tiempo real, hay dos cosas principales que debe hacer. Primero, debe decirle al reloj que está comenzando un entrenamiento (digamos que está corriendo):

// Create a new workout session self.workoutSession = HKWorkoutSession(activityType: .Running, locationType: .Indoor) self.workoutSession!.delegate = self; // Start the workout session self.healthStore.startWorkoutSession(self.workoutSession!)

Luego, puede iniciar una consulta de transmisión desde HKHealthKit para brindarle actualizaciones a medida que HealthKit las reciba:

// This is the type you want updates on. It can be any health kit type, including heart rate. let distanceType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning) // Match samples with a start date after the workout start let predicate = HKQuery.predicateForSamplesWithStartDate(workoutStartDate, endDate: nil, options: .None) let distanceQuery = HKAnchoredObjectQuery(type: distanceType!, predicate: predicate, anchor: 0, limit: 0) { (query, samples, deletedObjects, anchor, error) -> Void in // Handle when the query first returns results // TODO: do whatever you want with samples (note you are not on the main thread) } // This is called each time a new value is entered into HealthKit (samples may be batched together for efficiency) distanceQuery.updateHandler = { (query, samples, deletedObjects, anchor, error) -> Void in // Handle update notifications after the query has initially run // TODO: do whatever you want with samples (note you are not on the main thread) } // Start the query self.healthStore.executeQuery(distanceQuery)

Todo esto se describe en detalle en la demostración al final del video Novedades en HealthKit - WWDC 2015


Muchos de los kits de software para iOS ahora están disponibles para watchOS, como HealthKit. Puedes usar las funciones y clases de HealthKit (HK) para calcular las calorías quemadas, encontrar el ritmo cardíaco, etc. Puedes usar HKWorkout para calcular todo sobre los entrenamientos y acceder a las variables relacionadas, como el ritmo cardíaco, como hiciste antes con iOS. Lee las documentaciones de desarrolladores de Apple para aprender sobre HealthKit. Se pueden encontrar en developer.apple.com.


Puede obtener datos de frecuencia cardíaca iniciando un entrenamiento y consultar datos de frecuencia cardíaca de healthkit.

Pregunte por la premisión para leer los datos del entrenamiento.

HKHealthStore *healthStore = [[HKHealthStore alloc] init]; HKQuantityType *type = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]; HKQuantityType *type2 = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning]; HKQuantityType *type3 = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned]; [healthStore requestAuthorizationToShareTypes:nil readTypes:[NSSet setWithObjects:type, type2, type3, nil] completion:^(BOOL success, NSError * _Nullable error) { if (success) { NSLog(@"health data request success"); }else{ NSLog(@"error %@", error); } }];

En AppDelegate en iPhone, responda esto esta solicitud

-(void)applicationShouldRequestHealthAuthorization:(UIApplication *)application{ [healthStore handleAuthorizationForExtensionWithCompletion:^(BOOL success, NSError * _Nullable error) { if (success) { NSLog(@"phone recieved health kit request"); } }]; }

Luego implementa Healthkit Delegate:

-(void)workoutSession:(HKWorkoutSession *)workoutSession didFailWithError:(NSError *)error{ NSLog(@"session error %@", error); } -(void)workoutSession:(HKWorkoutSession *)workoutSession didChangeToState:(HKWorkoutSessionState)toState fromState:(HKWorkoutSessionState)fromState date:(NSDate *)date{ dispatch_async(dispatch_get_main_queue(), ^{ switch (toState) { case HKWorkoutSessionStateRunning: //When workout state is running, we will excute updateHeartbeat [self updateHeartbeat:date]; NSLog(@"started workout"); break; default: break; } }); }

Ahora es el momento de escribir [self updateHeartbeat: date]

-(void)updateHeartbeat:(NSDate *)startDate{ __weak typeof(self) weakSelf = self; //first, create a predicate and set the endDate and option to nil/none NSPredicate *Predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:nil options:HKQueryOptionNone]; //Then we create a sample type which is HKQuantityTypeIdentifierHeartRate HKSampleType *object = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]; //ok, now, create a HKAnchoredObjectQuery with all the mess that we just created. heartQuery = [[HKAnchoredObjectQuery alloc] initWithType:object predicate:Predicate anchor:0 limit:0 resultsHandler:^(HKAnchoredObjectQuery *query, NSArray<HKSample *> *sampleObjects, NSArray<HKDeletedObject *> *deletedObjects, HKQueryAnchor *newAnchor, NSError *error) { if (!error && sampleObjects.count > 0) { HKQuantitySample *sample = (HKQuantitySample *)[sampleObjects objectAtIndex:0]; HKQuantity *quantity = sample.quantity; NSLog(@"%f", [quantity doubleValueForUnit:[HKUnit unitFromString:@"count/min"]]); }else{ NSLog(@"query %@", error); } }]; //wait, it''s not over yet, this is the update handler [heartQuery setUpdateHandler:^(HKAnchoredObjectQuery *query, NSArray<HKSample *> *SampleArray, NSArray<HKDeletedObject *> *deletedObjects, HKQueryAnchor *Anchor, NSError *error) { if (!error && SampleArray.count > 0) { HKQuantitySample *sample = (HKQuantitySample *)[SampleArray objectAtIndex:0]; HKQuantity *quantity = sample.quantity; NSLog(@"%f", [quantity doubleValueForUnit:[HKUnit unitFromString:@"count/min"]]); }else{ NSLog(@"query %@", error); } }]; //now excute query and wait for the result showing up in the log. Yeah! [healthStore executeQuery:heartQuery]; }

También tienes un turno en Healthkit en capbilities. Deja un comentario a continuación si tienes alguna pregunta.


Puede usar HKWorkout , que es parte del marco de HealthKit.