Flutter 真机和模拟器中未出现 HealthKit Permission 弹出窗口

发布于 2025-01-16 09:59:16 字数 1111 浏览 4 评论 0原文

我在flutter中使用了health package来获取Android中的步数和跑步数据Google Fit和身体活动权限设置完美,但在 iOS 中,它不要求健康套件权限,所有其他权限都工作得很好,这是我为权限请求编写的代码

  Future<void> requestActivityPermission() async {
    if (Platform.isAndroid) {
      final permissionStatus = await Permission.activityRecognition.request();
      if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
        _activityPermanenetlyDeniedCase();
        return;
      } else {
        permissionStatus.isGranted;
        fetchTotalStepData();
      }
    } else {
      final permissionStatus = await Permission.activityRecognition.request();
      if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
        _activityPermanenetlyDeniedCase();
        return;
      } else {
        permissionStatus.isGranted;
        fetchTotalStepData();
      }
    }
  }

requestActivityPermission 函数在 initState 方法中调用。

_activityPermanenetlyDeniedCase 函数直接打开,在该函数中我有一个显示打开设置的对话框,但在该设置中没有 healthkit 权限。

我期待 healthKit 的弹出许可

I had used the health package in flutter for steps and running data in android the google fit and physical activity permission are set perfectly but in iOS, it is not asking for health kit permission all other permissions are working perfectly fine here is the code which I had written for permission request

  Future<void> requestActivityPermission() async {
    if (Platform.isAndroid) {
      final permissionStatus = await Permission.activityRecognition.request();
      if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
        _activityPermanenetlyDeniedCase();
        return;
      } else {
        permissionStatus.isGranted;
        fetchTotalStepData();
      }
    } else {
      final permissionStatus = await Permission.activityRecognition.request();
      if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
        _activityPermanenetlyDeniedCase();
        return;
      } else {
        permissionStatus.isGranted;
        fetchTotalStepData();
      }
    }
  }

The requestActivityPermission function is called in the initState Method.

The _activityPermanenetlyDeniedCase function directly opens up, in that function i had a dialog box showing open setting, but in the setting there is no healthkit permission.

I am expecting a popup permission for healthKit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

他是夢罘是命 2025-01-23 09:59:16

您需要在 ios/ 目录下的 Info.plist 文件中指定您使用的权限。

<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>

请参阅此处

You need to specify which permission you are using in Info.plist file under ios/ directory.

<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>

Refer here

愿得七秒忆 2025-01-23 09:59:16

检查 healthkit 是否在调试和发布选项卡中均已激活

Check that the healthkit is activated in both the debug and release tabs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文