标签: healthkit

打开 Health 并通过 URL Scheme 进入 App 的权限

我们可以直接链接到 Sources 然后是我的应用程序吗?我试图打开一个像这样的 URL,x-apple-health://sources/MyApp但它只打开源,而不是直接进入 MyApp。任何人都知道这是否可能?

编辑:这不是从另一个应用程序复制Open HealthKit 应用程序,因为我知道如何打开 Health 应用程序本身 - 我想知道是否可以直接进入应用程序的权限,而不仅仅是一般的“来源”选项卡。

ios healthkit

7
推荐指数
1
解决办法
1494
查看次数

实时获取 Apple Watch heartRateVariabilitySDNN?

我正在使用下面的函数来获取 heartRateVariabilitySDNN,但它只获取一次并且不能像 heartbeat 那样实时计算?

 func HRVstart() {
                        guard let quantityType = HKObjectType.quantityType(forIdentifier: .heartRateVariabilitySDNN) else { return }
                        
                        
                        self.healthStore.execute(self.HRVStreamingQuery())
                
                        // Create query to receive continiuous heart rate samples.
                        let datePredicate = HKQuery.predicateForSamples(withStart: Date(), end: nil, options: .strictStartDate)
                        let devicePredicate = HKQuery.predicateForObjects(from: [HKDevice.local()])
                        let queryPredicate = NSCompoundPredicate(andPredicateWithSubpredicates:[datePredicate, devicePredicate])
                        let updateHandler: HKQueryUpdateHandler = { [weak self] query, samples, deletedObjects, queryAnchor, error in
                            if let quantitySamples = samples as? [HKQuantitySample] {
                                self?.HRVprocess(samples: quantitySamples)
                            }
                        }
                        let query = HKAnchoredObjectQuery(type: quantityType,
                                                          predicate: queryPredicate,
                                                          anchor: nil, …
Run Code Online (Sandbox Code Playgroud)

ios swift healthkit apple-watch watchos

7
推荐指数
1
解决办法
941
查看次数

如何让 WidgetKit 上的现有条目保持刷新?

我正在HealthKit我的小部件中使用数据。如果手机被锁定,则无法获取HealthKit数据,除非手机解锁。但是,即使手机被锁定,我的小部件时间线也会尝试更新。

是否有可能以某种方式返回空完成,因此它将保持当前小部件数据不变?

这是我的代码:

struct Provider: IntentTimelineProvider {
    private let healthKitService = HealthKitService()
    func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        let currentDate = Date()
        let refreshDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)!
        
        healthKitService.getHeartRate() { data, error in
            
            //Create an empty entry
            var entry = SimpleEntry(date: currentDate, configuration: ConfigurationIntent(), data: nil)

            //If no errors, set data
            if(error == nil) {
                entry.data = data
            } else {
                print(error) //this runs when a …
Run Code Online (Sandbox Code Playgroud)

ios swift healthkit widgetkit swiftui

7
推荐指数
1
解决办法
1005
查看次数

Apple healthKit 快速眼动睡眠、深度睡眠、浅度睡眠分析

我正在开发一个 IOS 睡眠应用程序,我需要在其中进行睡眠分析。我正在使用 Healthkit 获取睡眠数据,我可以使用以下代码成功获取睡眠分析数据:

func retrieveSleepAnalysis(from startDate: Date?, to endDate: Date? , completion: @escaping ([HKCategorySample], Error?) -> Void) {
guard let sleepType = HKObjectType.categoryType(forIdentifier: .sleepAnalysis) else { return}
        let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: .strictStartDate)
        let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)
        let query = HKSampleQuery(sampleType: sleepType, predicate: predicate, limit: 10000, sortDescriptors: [sortDescriptor]) { (query, result, error) in
            if error != nil {
                completion([], error)
                return
            }
            if let result = result {
                let samples = result.compactMap({ …
Run Code Online (Sandbox Code Playgroud)

ios swift healthkit

7
推荐指数
1
解决办法
1473
查看次数

来自CMPedometer和HealthKit的数据之间的差异

下图列出了HealthKit与CMPedomoter类的步骤数据:

    HealthKit   CMPedometer  difference
1   2710        2681         -29
2   2569        2580          11
3   2367        2312         -55    
4   1326        1311         -15
5   2728        2711         -17
6   860         886           26
7   6293        6299           6
Run Code Online (Sandbox Code Playgroud)

两者之间每天都有细微的差别.有谁知道为什么会这样?没有其他应用程序正在向此设备写入步骤数据.

ios swift healthkit

6
推荐指数
1
解决办法
1153
查看次数

有没有办法在 Apple Watch 模拟器上模拟锻炼?

有没有办法在 Apple Watch sim 上模拟锻炼?测试锻炼应用程序、健康监测器等真的很有用。我正在运行 Xcode 7 beta,但找不到它的选项。我在互联网上搜索有关如何完成的任何提示,但到目前为止还没有发现任何有趣的东西。

WWDC的HealthKit 演讲者能够做到这一点。(观看大约 35 分钟):D

xcode ios healthkit apple-watch

6
推荐指数
1
解决办法
1640
查看次数

缺少 HealthKit 权利

我正在尝试将 HealthKit 与我正在构建的应用程序集成,并且我似乎已成功添加了它的权利。我已经使用适当的应用程序 ID 创建并下载了配置文件,并且 Xcode 功能选项卡中的 HealthKit 切换似乎看起来不错:

但是,当我运行该应用程序时,出现以下错误:

HealthKit authorization denied!
Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo={NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}
Run Code Online (Sandbox Code Playgroud)

这是一个奇怪的错误消息,因为Add the "HealthKit" entitlement to your App ID已经检查为已成功完成。

但是,一旦我收到该错误,检查的应用程序 ID 权利就会更改为:

但是在我的开发者帐户的App ID中,App ID显示HealthKit确实已启用。

它在我的配置文件中显示了相同的内容。

而且我只有一个应用程序 ID 和一个配置文件可供选择,因此我不可能将它们混淆。

xcode entitlements ios swift healthkit

6
推荐指数
1
解决办法
4842
查看次数

对于由苹果的 Health App - HealthKit - iOS 创建的健康数据,HKMetadataKeyTimeZone 始终为零

我正在使用 HealthKit 读取用户的健康数据。尝试从健康数据中获取时区信息,以确定健康活动发生在哪个确切时区。为此,我依赖 HealthKit 元数据中的“HKMetadataKeyTimeZone”键。但即使对于苹果健康应用程序自动记录的健康数据,“HKMetadataKeyTimeZone”键的值也始终为零。在苹果健康应用程序上手动输入的数据也存在同样的问题。

那么是否有其他键/方式可以给出每个样本的时区信息?

或者苹果的健康应用程序根本没有记录健康数据的时区信息?

或者苹果的健康应用程序正在记录健康数据的时区信息,而不是通过 HealthKit 框架将其提供给开发人员?

下面的博客文章说,samples retrieved from HealthKit do not have time zone information associated with them, unless the creating application captures that information in the metadata property using the predefined HKMetadataKeyTimeZone key.
Even Apple fails to add the time zone metadata to samples generated through their own Health app.

http://www.openmhealth.org/3-painful-lessons-learned-building-with-healthkit/


下面是我的代码:

import HealthKit

let healthKitStore: HKHealthStore = HKHealthStore()


func getHealthDataValue_QuantityType(healthQuantityType : HKQuantityType?, strUnitType : String)
{
  if let healthQuantityType = healthQuantityType { …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift healthkit hkhealthstore

6
推荐指数
1
解决办法
997
查看次数

当应用程序在后台时如何查询HealthKit(HKWorkout)更新?

编辑以添加我的更新代码,该代码是我根据 WWDC 2016 的充分利用 Healthkit 演讲编写的,但除非我打开应用程序,否则我仍然无法获得新锻炼的打印声明。

将新的锻炼项目保存到 Apple Watch 后,我尝试在 iPhone 上进行观察。下面是我正在运行的代码didFinishLaunching。为了测试它,我在我的 iPhone 应用程序上运行 Xcode...构建并运行,然后导航回主屏幕。然后在我的手表上开始并保存锻炼,但是我的打印语句没有在控制台中打印。我缺少什么?

func startObservingNewWorkouts() {

    let sampleType =  HKObjectType.workoutType()

    //1. Enable background delivery for workouts
    self.healthStore.enableBackgroundDelivery(for: sampleType, frequency: .immediate) { (success, error) in
        if let unwrappedError = error {
            print("could not enable background delivery: \(unwrappedError)")
        }
        if success {
            print("background delivery enabled")
        }
    }

    //2.  open observer query
    let query = HKObserverQuery(sampleType: sampleType, predicate: nil) { (query, completionHandler, error) in

        self.updateWorkouts() {
            completionHandler()
        }


    } …
Run Code Online (Sandbox Code Playgroud)

background-process ios appdelegate swift healthkit

6
推荐指数
1
解决办法
3547
查看次数

打开使用 Health Kit 的应用程序的 Health Kit 权限设置

我正在使用 Health Kit 为用户显示步骤信息。

let healthKitTypes: Set = [ HKObjectType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!]

self.healthStore.requestAuthorization(toShare: healthKitTypes, read: healthKitTypes) { (bool, error) in
    
    if (bool) {
        // Auth granted
    } else {
        // Navigate user to HealthKit app permissions
    }
}
Run Code Online (Sandbox Code Playgroud)

此代码向用户显示一个具有所要求权限的弹出窗口。我想要做的是// Navigate user to HealthKit app permissions,如果用户未批准弹出窗口的权限,则直接为我的应用程序打开 Health Kit 应用程序权限设置。

我知道可以使用以下方式打开应用程序的设置:

let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in

    guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
        return
    }

    if UIApplication.shared.canOpenURL(settingsUrl) {
        UIApplication.shared.open(settingsUrl, completionHandler: { (success) in …
Run Code Online (Sandbox Code Playgroud)

swift healthkit

6
推荐指数
0
解决办法
1533
查看次数