agencyenterprise / react-native-health

A React Native package to interact with Apple HealthKit
MIT License
841 stars 232 forks source link

Permissions always returned denied even though user approved #262

Open amandadahlin opened 1 year ago

amandadahlin commented 1 year ago

Describe the bug I'm having issues with the permissions. The users are prompted with the approve permissions to share read access to their StepCount, Workout, DistanceWalkingRunning and FlightsClimbed data. Even though they approve all I get status denied. All of them are set to approved when checking the Apple Health app and sharing tab.

To Reproduce

  1. Initialize AppleHealthKit.initHealthKit ... when navigating to that component
  2. Approve all read permissions when that is prompted
  3. Checking auth status is status 1 (SharingDenied)

Expected behavior Once user approved permissions auth status should be set to 2 (SharingAuthorized) and data should be fetched from Apple Health.

Screenshots

apple health sharing insights

Smartphone (please complete the following information):

Additional context

GGGava commented 1 year ago

Hello @amandadahlin did you manage to work around this? Is this still an issue?

gbrvalerio commented 1 year ago

+1 happening here

swaroopbutala commented 1 year ago

I see the same issue as well..

GGGava commented 1 year ago

Hey ppl 😄

After taking a better look at this issue, I need to clarify some things:

Our docs mentions that getAuthStatus should return all types as SharingAuthorized, although this isn't what is currently happening. Both the read and the write fields of the getAuthStatus return are being populated by the write authentication status, which is wrong.

tldr: Lib is bugged and returning the write auth status as the read auth status.

Honestly, I believe you can just ignore the read auth status, as HealthKit doesn't even allow us to get them.

GGGava commented 1 year ago

To contributors:

I believe we should deprecate this function in favor of one without anything related to read permissions, as it's pointless and just misleading. I can do that in the next few days, but contributions until that are welcome 😄.

pjsandwich commented 1 year ago

I have noticed the following behavior in addition to the above described behavior. I currently am sharing read permissions for HeartRate, RestingHearRate, SleepAnalysis, and ActivitySummary. Here is my request:

const permissions = {
        permissions: {
          read: [
            'HeartRate',
            'RestingHeartRate',
            'SleepAnalysis',
            'ActivitySummary',
          ],
          write: ['HeartRate', 'HeartRateVariability'],
        },
      }

      AppleHealthKit.getAuthStatus(permissions, (err, results) => {
        if (err) {
          console.log('error getting Healthkit auth status: ', err)
        }

        if (results) {
          console.log('results: ', results)
        }
      })

And this is the response:

results:  Object {
  "permissions": Object {
    "read": Array [
      1,
      1,
      1,
      1,
    ],
    "write": Array [],
  },
}

So it looks like in addition to receiving the confusing 1 value for reads, it looks like I'm not getting the same length response for other types (see where I have HeartRate which is authorized as read but not write, while HeartRateVariability - of which I have neither read nor write - doesn't return any value for write)

StepsInvesting commented 4 months ago

The read permissions return 1 regardless of the state, so we're checking the steps from the last 48 hours and marking them as denied if the step count is zero. It's working very well. As for getAuthStatus, it is useful because it returns 0 if Apple Health hasn't been initiated before, or if it was closed without approving or denying the permissions.

ftaibi commented 1 month ago

getAuthStatus

The read permissions return 1 regardless of the state, so we're checking the steps from the last 48 hours and marking them as denied if the step count is zero. It's working very well. As for getAuthStatus, it is useful because it returns 0 if Apple Health hasn't been initiated before, or if it was closed without approving or denying the permissions.

checking the steps is smart I might try that

gbrvalerio commented 1 month ago

yup we actually did a similar workaround, but checking for sleep data (as it was the data we needed)