[Error] 18.2.1 HealthKit steps

From the date the app was updated, the step count data retrieved from HealthKit was strange. On the other hand, step count data from the date before the update is imported normally. After deleting and reinstalling the app, the problem did not occur. Is there anyone who has experienced something like this or knows the cause?

The HealthKit store on the device is not supposed to change when an app is updated, but without more details, it is hard to provide meaningful comment.

You might consider providing more context about your question, like the details of the "strange" behavior and the relevant code. See tips on writing forums posts, if necessary.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

func getStepRecords(from startDate: Date, to endDate: Date) async -> [StepData] {
var recordStepDatas = [StepData]()
let statistics = await getStepRecordsOneDays(from: startDate, to: endDate)
statistics.forEach { statistic in
let steps = statistic.sumQuantity()?.doubleValue(for: HKUnit.count()) ?? 0
recordStepDatas.append(
StepData(
steps: steps,
startedAt: statistic.startDate,
endedAt: statistic.endDate
)
)
}
return recordStepDatas
}
func getStepRecordsOneDays(from startDate: Date, to endDate: Date) async -> [HKStatistics] {
let intervals = DateComponents(day: 1)
let anchorDate = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: .now) ?? .now
return await withCheckedContinuation { continuation in
let query = HKStatisticsCollectionQuery.init(quantityType: stepCountType, quantitySamplePredicate: nil, options: .cumulativeSum, anchorDate: anchorDate, intervalComponents: intervals)
var staticsArray = [HKStatistics]()
query.initialResultsHandler = { _, results, _ in
results?.enumerateStatistics(from: startDate, to: endDate) { result, _ in
staticsArray.append(result)
}
continuation.resume(returning: staticsArray)
}
store.execute(query)
}

I recently ran into a similar problem again. Step count data has not been retrieved properly since a certain point in time. This issue does not seem to occur for all users, but only occasionally for a small number of users. Is there anything in my code that might be problematic?

[Error] 18.2.1 HealthKit steps
 
 
Q