Tag: 健康工具包

了解来自HKSourceQuery或一般来源的结果

我只是做了一个HKSourceQuery并得到了一些结果。 当我做了一个println的结果,我得到这个: <HKSource:0x156c1520 "Health" (com.apple.Health)>//description of the object 如何使用这个来做一个使用HKQuery.predicateForObjectsFromSource(/* source goes here */)的谓词HKQuery.predicateForObjectsFromSource(/* source goes here */)

从HealthKit获取一系列血糖logging

我正在使用swift关于HealthKit的一些教程,我正在遵循的教程之一是如何从HealthKit中检索一些数据,如体重,身高的年龄。 本教程将演示如何检索每个logging的最新logging,以下代码显示: 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 return the samples in descending order let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: false) // 3. we […]

HealthKit Watch应用程序没有logging卡路里

我无法获得任何卡路里/积极EnergyEurlur显示在我的应用程序,不知道为什么? 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: workoutStartDate, end: nil, options: .strictStartDate) let devicePredicate = HKQuery.predicateForObjects(from: [HKDevice.local()]) let queryPredicate = NSCompoundPredicate(andPredicateWithSubpredicates:[datePredicate, devicePredicate]) let updateHandler: ((HKAnchoredObjectQuery, [HKSample]?, [HKDeletedObject]?, HKQueryAnchor?, Error?) […]

HealthKit授权状态始终为1

我在我的应用程序中使用HealthKit。 我正在获取用户访问HealthKit数据的权限。 授权后,如果我检查特定HealthKit对象types的授权状态,则始终返回访问被拒绝。 (1是枚举整型值)。 这是我的代码 // Steps if ([self.healthStore authorizationStatusForType:[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]] == HKAuthorizationStatusSharingAuthorized) { [self accessStepsFrom:fromDate to:toDate]; } //Sleep if ([self.healthStore authorizationStatusForType:[HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis]] == HKAuthorizationStatusSharingAuthorized) { [self accessSleepFrom:fromDate to:toDate]; } //DOB if ([self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]] == HKAuthorizationStatusSharingAuthorized) { [self accessDOB]; } 方法[self.healthStore authorizationStatusForType:[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth]]总是抛出我1 。 需要帮助吗?

在iOS中的Health Kit App中显示月经详情

我有一个健康工具包对象,所有的设置都正确。 但是,我正在尝试检索健康套件的月经数据。 但是,我无法findHKQuantityTypeIdentifier (即HKCategoryValueMenstrualFlow )中的相应types。 HKCategoryValueMenstrualFlow有一些子项,如HKCategoryValueMenstrualFlowLight , HKCategoryValueMenstrualFlowMedium , HKCategoryValueMenstrualFlowHeavy 。 使用下面的方法,我写这样的代码: -(void)viewDidLoad { HKHealthStore *healthStore = [[HKHealthStore alloc] init]; HKCategoryType *q=[NSSet setWithObjects: [HKCategoryType categoryTypeForIdentifier:HKCategoryValueMenstrualFlowHeavy], [HKCategoryType categoryTypeForIdentifier:HKCategoryValueMenstrualFlowMedium], [HKCategoryType categoryTypeForIdentifier:HKCategoryValueMenstrualFlowLight], [HKCategoryType categoryTypeForIdentifier:HKCategoryValueMenstrualFlowUnspecified],nil]; [healthStore requestAuthorizationToShareTypes:shareObjectTypes readTypes: healthStore completion:^(BOOL success, NSError *error) { if(success == YES) { } } 我正在这样写。 但我的疑问是如何在健康工具包应用程序中显示月经数据的细节。 请告诉我任何人提供任何想法。 提前致谢。

HealthKit数据在后台无法访问

我想在后台使用后台提取来提取HealthStore数据,但是我不断收到错误: Error Domain=com.apple.healthkit Code=6 "Protected health data is inaccessible" UserInfo=0x17026fdc0 {NSLocalizedDescription=Protected health data is inaccessible} 。 苹果说: 由于HealthKit商店已encryption,因此手机locking时,应用程序无法从商店读取数据。 这意味着您的应用在后台启动时可能无法访问商店。 任何解决方法来访问背景中的数据? HKObserverQuery是在后台获取数据的唯一方法吗?

为什么HKAnchoredObjectQuery和enableBackgroundDeliveryForType总是在应用程序处于后台时触发?

我正在试验一下,以便熟悉HKAnchoredObjectQuery,并在我的应用程序处于非活动状态时获取结果。 我启动应用程序,切换到苹果健康,input血糖的结果; 有时会立即调用结果处理程序(如打印到控制台所certificate的那样),但有时在处理程序切换回我的应用程序之前,不会调用处理程序。 删除结果以及添加结果也是如此。 任何人有任何指导? 这些代码大部分是来自digital数据库的一个问题,在这里,当应用程序在后台并且login到控制台的时候,这个问题就可以在这里得到更新。 请参阅: iOS 9中的HealthKenAnchoredObjectQuery,不返回HKDeletedObject class HKClient : NSObject { var isSharingEnabled: Bool = false let healthKitStore:HKHealthStore? = HKHealthStore() let glucoseType : HKObjectType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBloodGlucose)! override init(){ super.init() } func requestGlucosePermissions(authorizationCompleted: (success: Bool, error: NSError?)->Void) { let dataTypesToRead : Set<HKObjectType> = [ glucoseType ] if(!HKHealthStore.isHealthDataAvailable()) { // let error = NSError(domain: […]

如何从Apple Watch获取传感器数据到iPhone?

有没有办法从Apple Watch获取传感器数据? 例如,我怎样才能连接并从苹果手表获得心率到我的应用程序? 这些是我需要在我的应用程序中执行的步骤: 定义一个委托来接收来自Apple Watch的心率信息。 向Apple Watch发送请求以定期发送数据 我知道它是如何工作的其他人力资源显示器超过BT。 界面是类似的吗? 还是应该依靠HealthKit来实现呢?

HealthKit HKAuthorizationStatus读取数据

我正在使用HealthKit来读取某些types的信息。 我特别不要求写function。 尝试检测用户是否允许读取某个健康types时,会出现问题。 我相信这样做的预期方法是使用HKHealthStore的authorizationStatusForType方法,但是这只会返回被拒绝或未知。 它只是返回授权的写入types。 有没有人find一种方法来使用这种方法阅读或另一个工作? HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight]; HKAuthorizationStatus status = [self.healthStore authorizationStatusForType:stepsType];

HealthKit Swift获取今天的步骤

我正在制作一个快速的iOS应用程序,它与Health应用程序报告的用户步数统一在一起。 我可以很容易地find用户的最后一个小时的步数,用这个作为我的谓词: let anHourBeforeNow: NSDate = NSDate().dateByAddingTimeInterval(-60 * 60) let predicate = HKQuery.predicateForSamplesWithStartDate(anHourBeforeNow, endDate: NSDate(), options: .None) 而剩下的部分,我可以成功访问用户的最后一个小时的步数。 但是,如何从一天开始访问用户的步骤数据,如健康应用程序显示在步骤部分? 我正在尝试做这样的事情: let date = NSDate() let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! let newDate = cal.startOfDayForDate(date) let predicate = HKQuery.predicateForSamplesWithStartDate(newDate, endDate: NSDate(), options: .None) 但是这段代码不会调整时区(所以它给了UTC的一天的开始,而不是用户的一天的开始),我也得到了高度膨胀的步数(原因未知)。 那么我怎样才能得到当前用户的步数,如同Health中报告的步数一样,如下图所示: