ios - 使用 WatchKit 和小部件(今天的扩展)保存/删除到 HealthKit?

标签 ios objective-c watchkit healthkit today-extension

这是一个我知道有答案的问题,因为我看到了执行此功能的应用程序。我试过(直接写,使用后台获取)但没有任何效果。我在应用程序商店中找到了一个应用程序,它具有我正在寻找的功能。后台获取设置为关闭且主应用程序不在后台运行。我转到小部件并添加一个项目。我打开 HealthKit,我看到了预期的数据。

我想为我的应用做同样的事情。我希望我今天的扩展(小部件)和/或 WatchKit 扩展能够写入 HealthKit 商店,即使应用程序没有在后台运行。 就像我说的那样,我已经测试了一个可以执行此功能的应用程序,即使在 Apple 文档中它是这样说的:

The HealthKit store can only be accessed by an authorized app. You cannot access HealthKit from extensions (like the Today view) or from a WatchKit app.

Because the HealthKit store is encrypted, your app cannot read data from the store when the phone is locked. This means your app may not be able to access the store when it is launched in the background. However, apps can still write data to the store, even when the phone is locked. The store temporarily caches the data and saves it to the encrypted store as soon as the phone is unlocked.

如有任何答案或见解,我们将不胜感激。谢谢大家。

最佳答案

健康数据存储确实在设备锁定时加密。锁定被定义为需要在设备上输入密码并且屏幕已关闭(因此在返回主屏幕之前需要输入密码或触摸 ID)。虽然商店是加密的,但无论应用程序是否在后台运行,都无法从中读取任何数据。即使在应用程序运行时设置观察者查询也不允许它继续被读取。我想这种级别的保护是通过使用数据保护功能和 NSFileProtectionComplete 来完成的。选项。

您在其他应用程序中观察到了哪些 HealthKit 功能?如果它显示的是步数和距离数据,那么他们很可能直接从计步器 (CMPedometer) 获取这些数据,这在设备锁定时不受限制。

关于ios - 使用 WatchKit 和小部件(今天的扩展)保存/删除到 HealthKit?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35016282/

相关文章:

android - 来自/root/.pub-cache/hosted/pub.dartlang.org 包的 Flutter 调试编译错误

ios - 无法显示uilabel的文字,自定义 View

ios - 为 watchOS 2.0 实现核心数据

ios - 如何计算 WatchKit 扩展中的当前位置

ios - Apple Watch 模拟器以通知 View 启动 watch 应用程序。如何在main中自动启动?

iOS removeFromSuperview 如果未添加到 superview 不会引发错误

iphone - 表格单元格的奇怪行为

iphone - iPhone 中的电子书阅读器 : alternatives to Web view

objective-c - 更新附加到 SKNode 的 SKShapeNode

objective-c - 星号 * 在 Objective-C 中是什么意思?