healthkit

HealthKit开发教程之HealthKit的复合数据

廉价感情. 提交于 2020-03-02 05:58:02
HealthKit开发教程之HealthKit的复合数据 复合数据就是复合单位和值构成的数据。所谓复合单位就是由单位进行乘法、除法等得到的单位,如 m/s 、 lb · ft 等就是复合单位。本节将针对这些复合数据进行讲解。 HealthKit的 相乘得到的复合数据 在物理学中我们可能接触过类似 lb · ft (扭矩单位,扭矩是使物体发生转动的一种特殊的力矩。)这样的单位。这种单位我们可以看做是两个单位相乘得到的复合单位。开发者如果想要在自己的程序中使用这种复合单位,首先需要对这种单位进行创建。创建这种单位需要使用到 unitMultipliedByUnit(_:) 方法,其语法形式如下: func unitMultipliedByUnit(_ unit: HKUnit!) -> HKUnit! 其中,参数 unit :用来指定被乘的单位。 【示例 2-44 : HKUnit-unitMultipliedByUnit 】下面显示汽车中发电机的扭矩,以“磅 . 英尺”为单位。代码如下: import UIKit import HealthKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup

iOS WatchOS5 - how to detect programmatically if Apple Watch was on the wrist (worn) at specific time interval?

与世无争的帅哥 提交于 2020-01-24 19:25:47
问题 I'm interested if there is some HealthKit or other data source I can query to know if the Apple Watch was worn/in contact with the wrist at a given time interval. Currently I'm relying on HealthKit query for HeartRate and it appears that if I get no heart rate readings within a certain window, then the watch was most likely off the wrist or charging. Is there a better way to detect if the Apple Watch was worn on the wrist? The problem with this method is that it is not very descriptive - if

Get an array of Blood Glucose records from HealthKit

[亡魂溺海] 提交于 2020-01-23 12:54:11
问题 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

Access workout data even when apple watch screen turn off

这一生的挚爱 提交于 2020-01-20 02:53:05
问题 I success to get heart rate data in live without workout session on apple watch os 2. But when apple watch screen turn off, my completion block is not anymore called. I would like to continue to manage these data in live and to make my phone ring when heart rate is too low. Maybe i can let the app on the iphone perma open and maybe it can access to the healthkit data during this workout ? Do you think this can work ? or do you have another idea ? Regards 回答1: Hey i found a solution : i keep

Deleting a Water Sample from HealthKit

こ雲淡風輕ζ 提交于 2020-01-11 07:18:48
问题 My application currently lets users save WaterIntakeRecord s and they are then persisted with Core Data. I am able to write to HealthKit, saving a water intake record as a HKQuantitySample . I add a WaterIntakeRecord into my application with an amount of 12.9 fluid ounces. Since in Health, I have milliliters as my preferred unit of measurement, it shows in milliliters: Where I am struggling is when trying to delete a sample. When the user saves a WaterIntakeRecord , they can choose the unit

Open HealthKit App from another app

依然范特西╮ 提交于 2020-01-10 18:22:10
问题 I want to build a fitness app that will upload the data to HealthKit. Is there any way to open/navigate to HealthKit from another app? 回答1: On iOS 10, the Health app URL scheme is x-apple-health . You can open it from within your own app by calling: Objective-C: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"x-apple-health://"]]; Swift: UIApplication.shared.open(URL(string: "x-apple-health://")!) See Open Health app using url scheme | Apple Developer Forums. 回答2: iOS does

Error 'cannot convert value of type 'int' to expected argument type 'UInt'

孤街浪徒 提交于 2020-01-07 07:44:14
问题 On the line var anchor = HKQueryAnchor(fromValue: Int(HKAnchoredObjectQueryNoAnchor)) I get the red flag error cannot convert value of type 'Int' to expected argument type 'Uint' I had copy-pasted the code from another Xcode project, which brought no error for this line in the other project (reading heart rate on watchOS only). Any ideas? let healthStore = HKHealthStore() //State of the app - is the workout activated var workoutActive = false // define the activity type and location var

Cannot detect device as iPad

你。 提交于 2020-01-06 13:52:50
问题 I'm making an app that uses HealthKit. The app must not work on an iPad, and as such my viewDidLoad method contains an if/then/else statement to show an alert to iPad users. This is my code: if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") && [HKHealthStore isHealthDataAvailable] == 1) { ... } else { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Whoops!" message:@"Looks like

Cannot detect device as iPad

只谈情不闲聊 提交于 2020-01-06 13:52:38
问题 I'm making an app that uses HealthKit. The app must not work on an iPad, and as such my viewDidLoad method contains an if/then/else statement to show an alert to iPad users. This is my code: if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone && SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") && [HKHealthStore isHealthDataAvailable] == 1) { ... } else { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Whoops!" message:@"Looks like

How to get Apple health data by date wise?

杀马特。学长 韩版系。学妹 提交于 2020-01-03 07:24:09
问题 Apple health app gives the data by Date wise as shown in below image. By using HealthKit i am fetching the steps data from apple health as let p1 = HKQuery.predicateForSamples(withStart: fromDate, end: Date(), options: .strictStartDate) let p2 = HKQuery.predicateForObjects(withMetadataKey: HKMetadataKeyWasUserEntered, operatorType: .notEqualTo, value: true) let timeSortDesriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)//as in health kit entry let quantityType =