嗨,我想在午夜后重置计步器,我是新手。我看过以前的问题,它们有些令人困惑
我看过计步器上的Apple文档,也看过过去关于Stackoverflow上计步器的问题
var count : Int = 0.
var cal = Calendar.current
var comps = cal.dateComponents([.year, .month, .day, .hour, .minute, .second], from: Date())
comps.hour = 0
comps.minute = 0
comps.second = 0
let timeZone = NSTimeZone.system
cal.timeZone = timeZone
let midnight = cal.date(from: comps)!
print("MIDNIGHT", midnight)
if(CMPedometer.isStepCountingAvailable()){
self.pedometer.startUpdates(from: midnight) { (data: CMPedometerData?, error) -> Void in
DispatchQueue.main.async(execute: { () -> Void in
if(error == nil){
self.numberOfSteps.text = "\(data!.numberOfSteps)"
}
})
}
}
我知道我必须创建一个计数器,但是我不知道何时使用它?任何帮助深表谢意