healthkit

Accessing data from HealthKit with Swift

一曲冷凌霜 提交于 2021-02-11 15:16:53
问题 I'm a complete noob at Swift (and Xcode), as a matter of fact, the only programming language I (somewhat) know is Javascript. I'm trying to make a Swift SpriteKit game, and I would like to access the number of calories burned in HealthKit. The idea is that my game will provide more points the more calories you burn using other apps like Endomondo. My app does not actually track anything, I would just like to access other data left by other apps in the Health App. Is this even possible? (I'm

HealthKit running distance does not add up correctly?

∥☆過路亽.° 提交于 2021-02-11 14:21:52
问题 If I use Apple Health Kit to fetch the route data for a given running workout, and add up distance between each sample, it does not match up with the Health App total distance. I don't understand why. Please check the blow simplified test code. Only thing I can think of, is that I don't take pauses and GPS dropouts into account in the code below - but this should make the computed distance longer, I think. I have workouts where the computed distance is 50-100 meters short (10km workout, no

Predicate to filter .asleep from sleepAnalysis

帅比萌擦擦* 提交于 2021-02-11 14:12:51
问题 I have a issue I'm trying to resolve at Calculate Asleep time in HealthKit using Swift. It is regarding only summing the .asleep values with my query. Through my research, I believe the solution resides in a predicate that filters this value. Then, I can use NSCompoundPredicate to merge the predicates together for my query. I just don't know how to reach it. Here is the predicate line I'm trying to use: let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options:

Is heartRate data from an HKWorkoutSession a moving average?

穿精又带淫゛_ 提交于 2021-02-11 13:56:07
问题 I'm using an HKWorkoutSession to get heart rate data every 5 seconds in workoutBuilder didCollectDataOf . The heart rates are reported as "beats/minute". The question is, are they calculated as moving averages, or just over the previous time interval? (I couldn't find this specified in the documentation anywhere.) For example, if you get the following heart rates: t=0: 69 beats/min t=5: 71 beats/min t=10: 72 beats/min ... Is each value an average of beat intervals over the past 60 seconds, or

How to speed up HKStatisticsCollectionQuery in iOS 9.3?

梦想的初衷 提交于 2021-02-11 07:11:11
问题 It seems HKStatisticsCollectionQuery is incredibly slow in iOS 9.3. It can take upwards of 40 seconds to return hourly statistics for a year for active calories where it took 1 or less before. let predicate = HKQuery.predicateForSamplesWithStartDate(anchorDate, endDate: endDate, options: []) let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: statisticOptions, anchorDate: anchorDate, intervalComponents: interval) 回答1: After many

How to speed up HKStatisticsCollectionQuery in iOS 9.3?

☆樱花仙子☆ 提交于 2021-02-11 07:09:46
问题 It seems HKStatisticsCollectionQuery is incredibly slow in iOS 9.3. It can take upwards of 40 seconds to return hourly statistics for a year for active calories where it took 1 or less before. let predicate = HKQuery.predicateForSamplesWithStartDate(anchorDate, endDate: endDate, options: []) let query = HKStatisticsCollectionQuery(quantityType: quantityType, quantitySamplePredicate: predicate, options: statisticOptions, anchorDate: anchorDate, intervalComponents: interval) 回答1: After many

swift error "cannot assign value of type 'interface controller' to type HKWorkoutSessionDelegate'

会有一股神秘感。 提交于 2021-01-28 18:18:40
问题 I have an error message arising for watchOS code to measure heart rate in HealthKit, that is working fine in a different Xcode project. I've compared the code and they seem the same. the file is InterfaceController.swift. For the line 'self.workoutsession?.delegate = self' I get the red flag error "cannot assign value of type 'interface controller' to type HKWorkoutSessionDelegate" Any ideas? Here is the code for the function. The last para is the function with the error (The prior code is

swift error "cannot assign value of type 'interface controller' to type HKWorkoutSessionDelegate'

♀尐吖头ヾ 提交于 2021-01-28 18:10:29
问题 I have an error message arising for watchOS code to measure heart rate in HealthKit, that is working fine in a different Xcode project. I've compared the code and they seem the same. the file is InterfaceController.swift. For the line 'self.workoutsession?.delegate = self' I get the red flag error "cannot assign value of type 'interface controller' to type HKWorkoutSessionDelegate" Any ideas? Here is the code for the function. The last para is the function with the error (The prior code is

Error : Stopped workout session cannot be restarted

倖福魔咒の 提交于 2021-01-28 02:05:35
问题 I can start and stop a HealthKit workout session. But when I try to start a second workout after my first has stopped, I get the error: "workOutSession Error : Stopped workout session cannot be restarted" How do I start the next workout session (after the first has been stopped) without closing down and restarting the app? I am using Xcode 7.2, IOS9.2 and Watch OS 2.1 Stopping from InterfaceController: func startWorkout() { myExtensionConnectivity.startSession() myExtensionHealthKitManager

Get calories burned overnight from Health Kit

☆樱花仙子☆ 提交于 2021-01-20 09:26:20
问题 I use this function to get calories burned from Health Kit after syncing with RunKeeper func getActiveEnergy(currentDate: Date ,completion: @escaping ((_ totalEnergy: Double) -> Void)) { let calendar = Calendar.current var totalBurnedEnergy = Double() let startOfDay = Int((currentDate.timeIntervalSince1970/86400)+1)*86400 let startOfDayDate = Date(timeIntervalSince1970: Double(startOfDay)) // Get the start of the day let newDate = calendar.startOfDay(for: startOfDayDate) let startDate: Date =