我想创建一个标签,显示今日从HealthKit的步骤。我已尽可能允许HealthKit读取/写入数据,但我坚持实际获取数据。无法获得今天的步骤来显示标签
任何人都可以提供任何建议吗?这里是我的代码,包括我想要显示的步骤标签:
import Foundation
import UIKit
import HealthKit
class HealthKitPage : UIViewController
{
let healthStore: HKHealthStore = HKHealthStore()
override func viewDidLoad()
{
var shareTypes = Set<HKSampleType>()
shareTypes.insert(HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!)
var readTypes = Set<HKObjectType>()
readTypes.insert(HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)!)
healthStore.requestAuthorization(toShare: shareTypes, read: readTypes) { (success, error) -> Void in
if success {
print("success")
} else {
print("failure")
}
if let error = error { print(error) }
}
}
@IBOutlet weak var StepCount: UILabel!
}
你在哪里呈现步骤标记? – KKRocks