health-kit

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

大兔子大兔子 提交于 2019-12-08 06:32:24
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 background would be appreciated. class HealthKitManager { static let shared = HealthKitManager() private let

What is the cause of this HealthKit error: “An error occurred while adding a sample to the workout”?

醉酒当歌 提交于 2019-12-08 04:37:54
问题 I understand why, but the ambiguity of the errors that HealthKit puts out is a total black box. Why am I getting the error: An error occurred while adding a sample to the workout: The operation couldn’t be completed. I've been scouring the web for examples, but most of them are in swift. :( Here's my code: - (NSSet *)dataTypesToRead { HKQuantityType *heartRate = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]; return [NSSet setWithObjects:heartRate, nil]; } -

Error in HealthKit: Error Domain=com.apple.healthkit Code=100 “Failed to open database” UserInfo= {NSLocalizedDescription=Failed to open database}

依然范特西╮ 提交于 2019-12-08 01:39:15
问题 We're getting an error on a certain few devices when trying to authorize with the HealthKit API. The call to [HKHealthStore requestAuthorizationToShareTypes:::] fails consistently with the following error and the system-generated "Allow access to Health App" modal never gets presented: Error Domain=com.apple.healthkit Code=100 "Failed to open database" UserInfo= {NSLocalizedDescription=Failed to open database} We have a device that is able to reproduce this consistently, even after force

Try HealthKit with the iOS Simulator without developer account

混江龙づ霸主 提交于 2019-12-07 20:19:19
问题 I would like to test a HealthKit app in the iOS Simulator without an iPhone Developer Account. I added an entitlement file with the com.apple.developer.healthkit capability enabled and when I build the app it seems to include the file in the bundle but then when I try to access the HealthKit API the Simulator throws this error: Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo=0x7fc939f091c0 {NSLocalizedDescription=Missing com.apple

Open Apple Health programmatically

我的未来我决定 提交于 2019-12-06 22:56:25
问题 Is it possible to open the Health app programmatically, like one can do with the Settings app? If it's not possible to open the app's Apple Health permissions screen directly, can we at least open the main Apple Health screen? Edit : I know that I cannot request permissions again - just like with other things like Camera access, etc. However, if the user refuses Camera permissions, I can direct them to the Settings page directly where they can change those permissions. NSURL *url = [NSURL

Calories not being recorded for HealthKit Watch app

自作多情 提交于 2019-12-06 17:57:05
问题 I can't get any calories/activeEnergyBurned to show up in my app, and don't know why? WorkoutInterfaceController : private func totalCalories() -> Double { return totalEnergyBurned.doubleValue(for: HKUnit.kilocalorie()) } private func setTotalCalories(calories: Double) { totalEnergyBurned = HKQuantity(unit: HKUnit.kilocalorie(), doubleValue: calories) } func startQuery(quantityTypeIdentifier: HKQuantityTypeIdentifier) { let datePredicate = HKQuery.predicateForSamples(withStart:

How to Check if HealthKit has been authorized

倖福魔咒の 提交于 2019-12-06 17:23:57
问题 I want to check if HeathKit has been authorized for me to read the user's data, if I'm authorized segue to the workouts, if not pop an alert. But requestAuthorizationToShareTypes always seems to return true? How can I get a reference to whether the user has authorized me or not? override func viewDidLoad() { super.viewDidLoad() //1. Set the types you want to read from HK Store let healthKitTypesToRead: [AnyObject?] = [ HKObjectType.workoutType() ] //2. If the store is not available (for

Understanding results from HKSourceQuery, or Sources in general

有些话、适合烂在心里 提交于 2019-12-06 15:58:32
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 */) Here is the sample code in Obj-c, NSSortDescriptor *timeSortDesriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO]; HKQuantityType *quantityType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned]; HKSourceQuery *sourceQuery = [

Displaying Menstruation Details in Health Kit App in iOS

送分小仙女□ 提交于 2019-12-06 15:24:50
问题 I have a health kit object with all the proper setup; however, I am trying to retrieve the menstruation data of health kit. However, I cannot be able to find out the corresponding type in HKQuantityTypeIdentifier (i.e. HKCategoryValueMenstrualFlow ). The HKCategoryValueMenstrualFlow is having some of the sub items such as HKCategoryValueMenstrualFlowLight , HKCategoryValueMenstrualFlowMedium , HKCategoryValueMenstrualFlowHeavy . Using the following method, I am writing my code like this: -

Get an array of Blood Glucose records from HealthKit

北城以北 提交于 2019-12-06 09:04:27
I'm following some tutorials on HealthKit using swift, one of the tutorials I'm following is how to retrieve some data from the HealthKit such as weight, height age. The tutorial shows how to retrieve the most recent record for each them, the following codes shows that: func readMostRecentSample(sampleType:HKSampleType , completion: ((HKSample!, NSError!) -> Void)!) { // 1. Build the Predicate let past = NSDate.distantPast() as! NSDate let now = NSDate() let mostRecentPredicate = HKQuery.predicateForSamplesWithStartDate(past, endDate:now, options: .None) // 2. Build the sort descriptor to