health-kit

Getting yesterdays steps from HealthKit

只愿长相守 提交于 2019-12-10 14:23:46
问题 I'm building an app for personal use, and I am currently stuck on how to accurately get yesterdays steps from the healthkit. And then from there, placing it into a variable (should be easy, I know). I have a HealthKitManager class that calls the function from inside a view, and then appends that to a variable from that same view. I have scoured most of the healthKit questions, and I get back data, but I don't think it is accurate data. My phone data from yesterday is 1442 steps, but it's

Understanding results from HKSourceQuery, or Sources in general

最后都变了- 提交于 2019-12-10 11:42:14
问题 I just did a HKSourceQuery and got some results. When I do a println of the results, I got this: <HKSource:0x156c1520 "Health" (com.apple.Health)>//description of the object How do I use this to make a predicate using the HKQuery.predicateForObjectsFromSource(/* source goes here */) 回答1: Here is the sample code in Obj-c, NSSortDescriptor *timeSortDesriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO]; HKQuantityType *quantityType = [HKQuantityType

How to get walking and running distance using HealthKit in swift

限于喜欢 提交于 2019-12-10 10:24:42
问题 I'm making Health App. I want to get walkingRunningDistance from HealthKit in Swift. But, I have a problem. Return value is 0.0mile. Why return value is 0 mile? My code is this. func recentSteps3(completion: (Double, NSError?) -> () ){ let type = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning) let date = NSDate() let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! let newDate = cal.startOfDayForDate(date) let predicate = HKQuery

Health handles multiple step sources differently than HealthKit—swift

家住魔仙堡 提交于 2019-12-10 04:34:19
问题 My Swift iOS app connects with HealthKit to show the user how many steps they have taken so far in the day. For the most part, this is successful. When the sole source of steps is steps recorded by the iPhone's built-in pedometer function, everything works fine and the step count shown by my app matches with the Health app's step count. However, when there are multiple sources of data—on my personal iPhone, my Pebble Time smartwatch and the iPhone's pedometer both feed steps to Health—my app

HealthKit Permission Sheet Not Appearing

亡梦爱人 提交于 2019-12-10 02:24:54
问题 In my watch extension I call this function: func requestAuthorization() { let healthStore = HKHealthStore() let workoutType = HKObjectType.workoutType() let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate) //reading let readingTypes = Set([heartRateType!, workoutType]) //writing let writingTypes = Set([heartRateType!, workoutType]) //auth request healthStore.requestAuthorization(toShare: writingTypes, read: readingTypes) { (success, error) -> Void in if error != nil {

How to solve this error with healthkit?

我是研究僧i 提交于 2019-12-09 06:49:38
问题 I'm adding code for healthkit in my ios Swift app, but I'm getting an error... /* Ask for permission to access the health store */ override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) if HKHealthStore.isHealthDataAvailable(){ healthStore.requestAuthorizationToShareTypes(typesToShare, readTypes: typesToRead, completion: {(succeeded: Bool, error: NSError!) in if succeeded && error == nil{ println("Successfully received authorization") } else { if let theError = error{

I can't get HealthKit to work. Missing Entitlement

混江龙づ霸主 提交于 2019-12-08 19:16:27
问题 I am having a hard time to get HealthKit working for my iOS App. I have done all the steps I have found so far and none seem to solve my problem I keep getting this error when trying to authorize Healthkit: Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo=0x78fa24e0 {NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.} Here is my code asking for authorization: if([HKHealthStore isHealthDataAvailable]) { self

How do I download Healthkit step and distance data?

隐身守侯 提交于 2019-12-08 13:23:31
I would like to download the step and distance data collected by the motion processor in the IPhone 5S (and later), and available in Apple's HealthKit, for analysis. What's the easiest/best way to do this? And clarifying (after new answers): is there any way to do it without writing a new iOS app? Are there any existing apps that provide the data, and/or any iCloud API that provides access. I'm not sure it can help you but this is how I get steps + (void)readUsersStepFromHK:(NSDate*)startDate end:(NSDate*)endDate { stepBegin=startDate; stepEnd=endDate; if ([HKHealthStore isHealthDataAvailable]

How to detect if HealthKit data is set from a device?

删除回忆录丶 提交于 2019-12-08 07:17:23
问题 I'm trying to fetch user steps from HealthKit and realised that users can add manually steps which I don't want to fetch. (For instance if they're cheating and setting 50k steps on one day). So I was thinking for a solution how to solve this problem and found out that maybe I could just filter all the result and fetch the data if the data was set by a device. I mean it could be set by an iPhone, but it can also be set by an Apple Watch. Here's how it looks when a user adds his/hers own steps

Write data to Firebase in the background after retrieving steps with HealthKit's background delivery

匆匆过客 提交于 2019-12-08 06:45:09
问题 I have an HKObserverQuery setup to fetch steps in the background ( enableBackgroundDelivery method is called in application:didFinishLaunchingWithOptions: ). The steps are retrieved in the background, but I would also like to store the retrieved steps in a Firebase database. This part is failing though, nothing is stored in Firebase. The method to store the steps does work correctly when the app is in the foreground. Any ideas on how to successfully write data in Firebase while in the