Health kit - Get shared health data along with my health data

I can able to get my health data list from health kit. I used below code to get my today's step count :

`func getTodaysSteps(completion: @escaping (Double) -> Void) {
    
    let stepsQuantityType = HKQuantityType.quantityType(forIdentifier: .stepCount)!
    
    let now = Date()
    let startOfDay = Calendar.current.startOfDay(for: now)
    let predicate = HKQuery.predicateForSamples(
        withStart: startOfDay,
        end: now,
        options: .strictStartDate
    )
    
    let query = HKStatisticsQuery(
        quantityType: stepsQuantityType,
        quantitySamplePredicate: predicate,
        options: .cumulativeSum
    ) { _, result, _ in
        guard let result = result, let sum = result.sumQuantity() else {
            completion(0.0)
            return
        }
        completion(sum.doubleValue(for: HKUnit.count()))
    }
    
    healthStore.execute(query)
}`

But i have one more health data of my brother, where he invited me to see his health data in my real device. Now i was not able to read / get his health data. Is there any way to get that.

Any solution would be great ...!

  • Because you might have been invited doesn't mean you can programmatically access his or anyone else's data.

  • Okay , thanks for your update

Add a Comment

Replies

--

No, the HealthKit API does not provide access to data that has been shared - only the local user's data (to the extent that your app has been granted permission, of course.)