ios - 如何在 Flutter 应用中高效使用 HealthKit 的步数功能?

标签 ios dart flutter healthkit

我正在研究一款必须为我们的初创公司构建的应用程序。

我想构建一个应用程序,通过在 iOS 上使用 HealthKit 来记录一个人每天的步数。

当用户请求刷新或重新启动应用程序时,我可以请求可用的最新步数。但是,我们希望在用户完成一定数量的步数(例如 10,000 步)后立即向他们推送通知。 所以我想知道是否可以在 flutter 中设置一个监听器,以便 HealthKit 能够(有效地)在进入时或按设定值/间隔提供最新的步数。

这种在 flutter 和 native Swift 代码之间进行通信的“监听器”架构是否可以通过 flutter 实现?如果可以,它是最好的方法吗? Android端也可以这样吗?

感谢您的关注。

最佳答案

也许HealthKitHKObserverQuery就是你在 iOS 端所需要的

Receiving Background Deliveries

Apps can also register to receive updates while in the background by calling the HealthKit store’s enableBackgroundDelivery(for:frequency:withCompletion:) method. This method registers your app for background notifications. HealthKit wakes your app whenever new samples of the specified type are saved to the store. Your app is called at most once per time period defined by the frequency you specified when registering.

至于架构

communicates between flutter and native Swift code ... Is the same also possible on the Android

我相信您正在寻找Flutter Platform Channels您可以在哪里找到Swift Example

Flutter uses a flexible system that allows you to call platform-specific APIs whether available in Java or Kotlin code on Android, or in ObjectiveC or Swift code on iOS.

Flutter’s platform-specific API support does not rely on code generation, but rather on a flexible message passing style:

The Flutter portion of your app sends messages to its host, the iOS or Android portion of your app, over a platform channel.

The host listens on the platform channel, and receives the message. It then calls into any number of platform-specific APIs – using the native programming language – and sends back a response to the client, the Flutter portion of your app.

不幸的是,我没有看到任何existing Flutter HealthKit但希望可用的工具足以让您为 HealthKit 构建自己的桥梁。

Brandon Donnelson 的视频 Creating a Plugin也可能有帮助。

我不确定是否有 HealthKit 可以替代 Android。

关于ios - 如何在 Flutter 应用中高效使用 HealthKit 的步数功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49385165/

相关文章:

iphone - 将应用程序上传到 iTunes 时出现版权问题

objective-c - UIPageControl 被取消选择

flutter - 在 flutter block 中处理

api - Flutter从API获取数据以构建方法

flutter - Flutter/Dart中的openssl_public_encrypt()

ios - 从应用程序委托(delegate)快捷方式时, View Controller 中缺少选项卡栏

ios - PUT 方法的 Alamofire Content-Type application/json

html - 如何在 Dart 中创建 HTML 链接?

android-studio - 在 Android Studio Flutter 项目的上下文菜单中用未显示的列换行

dart - 在没有 Dart VM 的情况下将 Dart API 导出到 JavaScript