ios - 有没有办法从 Healthkit 获得多个数据点的集体许可
问题描述
我正在创建一个需要从 HealthKit 获取 heartRate、restingHeartRate、walkingHeartRateAverage、HeartRateVariabilitySDNN 数据的应用程序。
我还想获取用户的身体测量数据。即体重指数、体温、身高、腰围、体重。
要获得读取权限,我需要为每种数据类型获得单独的权限:
let healthKitTypesToRead: Set<HKObjectType> = [
HKObjectType.quantityType(forIdentifier: .heartRate)!,
HKObjectType.quantityType(forIdentifier: .heartRateVariabilitySDNN)!,
HKObjectType.quantityType(forIdentifier: .restingHeartRate)!,
HKObjectType.characteristicType(forIdentifier: .walkingHeartRateAverage)!,
HKObjectType.quantityType(forIdentifier: .bodyMass)!,
HKObjectType.quantityType(forIdentifier: .bodyMassIndex)!,
HKObjectType.quantityType(forIdentifier: .bodyTemperature)!,
HKObjectType.quantityType(forIdentifier: .height)!,
HKObjectType.quantityType(forIdentifier: .waistCircumference)!,
HKObjectType.quantityType(forIdentifier: .weight)!,
]
它在权限屏幕上显示了多个切换,我觉得对于用户来说,给每个单独的权限都太多了。(以防他们不想授予所有权限。)
有没有办法对权限进行分组,或者是否有一些数据类型,如果给予权限,我们也可以收集其他数据类型。
最初我认为允许 heartRate 意味着我可以获取 restingHeartRate、walkingHeartRateAverage 等。但它们都需要各自的权限。
解决方案
每个 HealthKit 类型必须独立授权:
为了帮助保护用户的隐私,HealthKit 需要细粒度的授权。在尝试访问或保存数据之前,您必须请求读取和共享应用程序使用的每种数据类型的权限。
https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data
Apple 预见到一次请求多个 HealthKit 类型的困难,并建议在您的应用程序中的不同时间而不是一次全部请求不同权限类型的权限:
但是,您不需要一次请求所有数据类型的权限。相反,等到您需要访问数据后再请求许可可能更有意义。
HealthHit 权限对话框也有一个按钮,允许用户启用所有请求的类型:
打开所有类别
推荐阅读
- javascript - React Native - 无法将状态变量传递给样式
- c# - 在 ASP.NET MVC 解决方案中,如何将多个 Word 模板组件组合到一个 Microsoft Word 文档中?
- javascript - 节点 postgres 约束
- linux - 在 exec 命令上插入 pwd
- javascript - 使复选框需要 JS/jQuery
- php - 从 PHP 中共享主机上的 cron 运行脚本时,如何使用 curl 绕过网站的接受 cookie?
- python - 在一行中从多返回函数中解包并分配单个返回值(Python)
- python - 在按钮上单击将字符发送到后台应用程序
- django - 将对象分组(不排序)到单个 Django 页面上的字母列表中
- python - python类的资源