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

How can I detect when a user denies permission or when the current permission is unavailable? #342

Open
Poovit-B opened this issue Oct 16, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Poovit-B
Copy link

Describe the bug

  1. First Attempt:
  • Used AppleHealthKit.initHealthKit for the first time.
  • Denied permission, but the response still returns 1.
  • Uncertain whether the user has allowed or not.
  1. Second Attempt:
  • Used AppleHealthKit.initHealthKit for the second time.
  • No permission dialog shown, but the response is still 1.
  1. HealthKit Availability Check:
  • Checked AppleHealthKit.isAvailable, and it returns true.
  1. Permission Status Check:
  • Checked AppleHealthKit.getAuthStatus.
    Returns {"permissions": {"read": [1, 1], "write": []}}.
  • No permission dialog is displayed; the result is directly returned.
import AppleHealthKit from 'react-native-health';

const PERMS = AppleHealthKit.Constants.Permissions;

export const permissions = {
    permissions: {
        read: [
            PERMS.StepCount,
            PERMS.Steps,
            PERMS.Workout,
            // PERMS.SleepAnalysis,
            // PERMS.ActiveEnergyBurned,
            // PERMS.BasalEnergyBurned,
            // PERMS.EnergyConsumed,
            // PERMS.ActivitySummary,
        ],
        write : []
    }
}
import AppleHealthKit from 'react-native-health';
import moment from 'moment';
import {permissions} from './permissions';

export const checkAppleHealth = async () => {
  return new Promise((resolve, reject) => {
    AppleHealthKit.isAvailable((err, results1) => {
      console.log('isAvailable results', results1);
      if (err) {
        console.log('error isAvailable Healthkit: ', err);
        resolve({success: false, ...results1});
      }
      AppleHealthKit.getAuthStatus(permissions, (err, results2) => {
        console.log('getAuthStatus results', results2);
        if (err) {
          console.log('error getAuthStatus Healthkit: ', err);
          resolve({success: false});
        }

        resolve({success: true, ...results2});
      });
    });
  });
};

export const authAppleHealth = () => {
  return new Promise((resolve, reject) => {
    AppleHealthKit.initHealthKit(permissions, (err, results) => {
      console.log('authAppleHealth results', results);
      console.log('err', err);
      if (err) {
        console.log('error initializing Healthkit: ', err);
        resolve({success: false, response: {error: err?.message}});
      }
      resolve({success: true});
    });
  });
};
@Poovit-B Poovit-B added the bug Something isn't working label Oct 16, 2023
@LinhLM23496
Copy link

+1

2 similar comments
@RameeshSayone
Copy link

+1

@nazim-kh4nzm
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants