Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[health 10.1.1] Health.hasPermissions don't works propely #939

Open
ifuterman opened this issue Apr 1, 2024 · 10 comments · May be fixed by #1091
Open

[health 10.1.1] Health.hasPermissions don't works propely #939

ifuterman opened this issue Apr 1, 2024 · 10 comments · May be fixed by #1091
Labels
bugfix a bug fix

Comments

@ifuterman
Copy link

ifuterman commented Apr 1, 2024

iOS emulator version 17.2

Emulator

Please complete the following information for each phone and/or emulator you're experiencing this bug on:

  • Device: [iPhone 15 Pro]
  • OS: [iOS 17.2]

Describe the bug

Regardless of the outcome, the result of the execution is always null

To Reproduce

  1. I manually add the steps with the health app
  2. Start app. In the popup, I restricted access to the health data. The result of the Health().requestAuthorization will be true, and the result of the Health().hasPermissions will be null. The x will be the empty list
  3. Open settings->Health grant access to all data
  4. Start app. The result of the Health().requestAuthorization will be true, and the result of all Health().hasPermissions will be null. The x will be the list with one element
const dataTypesIOS = <HealthTypeAndPermission>[
  HealthTypeAndPermission(healthType: HealthDataType.SLEEP_ASLEEP, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.STEPS, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.HEART_RATE, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.HEART_RATE_VARIABILITY_SDNN, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.RESTING_HEART_RATE, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.FORCED_EXPIRATORY_VOLUME, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.RESPIRATORY_RATE, access: HealthDataAccess.READ),
  HealthTypeAndPermission(healthType: HealthDataType.EXERCISE_TIME, access: HealthDataAccess.READ),
];
List<HealthTypeAndPermission> get dataTypes => Platform.isIOS ? dataTypesIOS : dataTypesAndroid;

Future<bool> authorize() async{
    _isInited = false;
    try{
      bool? permissions = await health.hasPermissions(
        dataTypes.map((e) => e.healthType).toList(),
        permissions: dataTypes.map((e) => e.access).toList()
      );
      if(permissions != null && permissions){
        _isInited = true;
        return true;
      }
      if(permissions == null || !permissions){
        _isInited = await health.requestAuthorization(
            dataTypes.map((e) => e.healthType).toList(),
            permissions: dataTypes.map((e) => e.access).toList()
        );
        //_isInited will be true always
        for(final dataType in dataTypes){
          final result = await health.hasPermissions([dataType.healthType], permissions: [dataType.access]);
          debugPrint('HealthService.authorise $result');
        }
        permissions = await health.hasPermissions(
            dataTypes.map((e) => e.healthType).toList(),
            permissions: dataTypes.map((e) => e.access).toList()
        );
        _isInited = permissions != null ? _isInited : false;
        final x = await health.getHealthDataFromTypes(DateTime.now().subtract(Duration(days: 20)), DateTime.now(), dataTypes.map((e) => e.healthType).toList());
        return _isInited ? true : false;
      }

    }catch (error){
      debugPrint('HealthWrapper.authorise EXCEPTION: ${error.toString()}');
    }
    return false;
  }

Expected behavior

If I have access to the parameter the result of the Health().hasPermissions needs to be not null; the result of the Health().requestAuthorization should depend on the request result.

Actual behavior

The result of the Health().hasPermissions is always null, even if I check specific allowed parameters with read access.
And I can read this parameter. Health().requestAuthorization always true

Flutter doctor

[✓] Flutter (Channel stable, 3.19.3, on macOS 14.3.1 23D60 darwin-arm64, locale ru-IL)
• Flutter version 3.19.3 on channel stable at /Users/iosiffuterman/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ba39319843 (4 weeks ago), 2024-03-07 15:22:21 -0600
• Engine revision 2e4ba9c6fb
• Dart version 3.3.1
• DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/iosiffuterman/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15C500b
• CocoaPods version 1.15.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.6)
• IntelliJ at /Applications/IntelliJ IDEA 2.app
• Flutter plugin version 78.4.2
• Dart plugin version 233.15026.12

[✓] VS Code (version 1.85.1)
• VS Code at /Users/iosiffuterman/Downloads/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available)
• iPhone Iosif Futerman (mobile) • 00008120-00181D0E0A70201E • ios • iOS 17.3.1 21D61
• iPhone 15 Pro (mobile) • EA6722F7-AF28-448E-8D7E-29F119F72565 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.3.1 23D60 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.87

[✓] Network resources
• All expected network resources are available.

• No issues found!

@ifuterman ifuterman added the bugfix a bug fix label Apr 1, 2024
@ifuterman ifuterman changed the title [health 10.1.1] Halth.hasPermissions don't works propely [health 10.1.1] Health.hasPermissions don't works propely Apr 3, 2024
@arsalancy
Copy link

I have the same problem. Did you manage to fix it?

@ifuterman
Copy link
Author

I have the same problem. Did you manage to fix it?

No. I downgraded to 9.0.0. For some reason, this version works, but the last doesn`t. I want to show popup, if the data reading restricted for me, because the iOS don't show embedded popup after the first time

@Some1Somewhere
Copy link

Any fix?

@MoritzMessner
Copy link

hey there,
In the documentation for the method hasPermissions you can read the following.

"As Apple HealthKit will not disclose if READ access has been granted for a data type due to privacy concern, this method can only return null to represent an undetermined status, if it is called on iOS with a READ or READ_WRITE access."

@samnbd
Copy link

samnbd commented Nov 15, 2024

checking if write permission of steps is granted on iOS (Apple health) is actually allowed by Apple, but for some reason Health().hasPermissions([HealthDataType.STEPS], permissions: [HealthDataAccess.WRITE]) always return false even though the write permission was granted

@byyoungjin
Copy link

Having same issue

@Maqcel
Copy link

Maqcel commented Dec 6, 2024

Having the same issues on 11.1.0 && 11.1.1

Health().hasPermissions(
        [HealthDataType.BODY_TEMPERATURE],
        permissions: [HealthDataAccess.WRITE],
      );

Problem was observed on iOS (13, system 17.7) but, I'm currently not able if something on android is wrong because got stuck on this for a long time now.
Returns false whenever it's call, if after granting it via system modal, or when granted inside health app.

@Maqcel
Copy link

Maqcel commented Dec 6, 2024

Currently I'm going to check if the version 9.0.0 is working as @ifuterman suggested it does

@Maqcel
Copy link

Maqcel commented Dec 6, 2024

Ok before that I tried version 10.0.0 and hasPermissions returns true/false properly

Edit 10.2.0 works as intended too, something was broken along the way

@ifuterman
Copy link
Author

I found the reason and made a PR. But we need to wait for approval. Then I'll do the adaptation for Android I'll do the fix for Android :)

@ifuterman ifuterman linked a pull request Dec 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix a bug fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants