gpt4 book ai didi

iOS Swift,如何区分使用 Apple Watch 和 iPhone 的步骤?

转载 作者:行者123 更新时间:2023-11-30 11:09:06 24 4
gpt4 key购买 nike

我正在使用 HealthKit 框架通过 HKSource 检索用户的步骤。在 Xcode Objective C 中,我使用 Bundle Identifier 来区分 watch/iPhone 中的步骤。但使用 Swift 我无法做到这一点。请建议。

提前致谢。

最佳答案

在查询选项中使用.separateBySource。例如:

guard let sampleType = HKObjectType.quantityType(forIdentifier: .stepCount)
else {
fatalError("Couldn't create the quantityType for .stepCount")
}
let calendar = Calendar.current
var dateComponents = DateComponents()
dateComponents.day = 1

var anchorComponents = calendar.dateComponents([.day, .month, .year], from: Date())
anchorComponents.hour = 0
guard let anchorDate = calendar.date(from: anchorComponents) else {
fatalError("Couldn't get the anchor date")
}

let stepsCumulativeQuery =
HKStatisticsCollectionQuery(quantityType: sampleType,
quantitySamplePredicate: nil,
options: [.cumulativeSum , .separateBySource],
anchorDate: anchorDate,
intervalComponents: dateComponents)

关于iOS Swift,如何区分使用 Apple Watch 和 iPhone 的步骤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52372888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com