我对 Swift 很陌生,所以我正在关注如何从这个页面制作计步器应用程序的教程:http: //shrikar.com/ios-swift-development-step-counter-app-using-pedometer-数据/
但是,那是不久前的事了,所以我一直在努力更新它,而且还没有走得太远。我不断收到此错误:
Cannot convert value of type '(CMPedometerData?, NSError?) -> Void' to expected argument type 'CMPedometerHandler' (aka '(Optional<CMPedometerData>, Optional<Error>) -> ()')
到目前为止,这是我的代码:
if(CMPedometer.isStepCountingAvailable()){
let fromDate = NSDate(timeIntervalSinceNow: -86400 * 7)
self.pedoMeter.queryPedometerDataFromDate(fromDate as Date, toDate: NSDate() as Date) { (data : CMPedometerData?, error: NSError?) -> Void in
DispatchQueue.main.async(){
if(error == nil){
self.steps.text = "\(data.numberOfSteps)"
}
}
}
self.pedoMeter.startPedometerUpdatesFromDate(newDay) { (data: CMPedometerData?, error: NSError?) -> Void in
DispatchQueue.main.async(){
if(error == nil){
self.steps.text = "\(data.numberOfSteps)"
}
}
}
}
错误发生在以下行:
{ (data : CMPedometerData?, error: NSError?) -> Void in
DispatchQueue.main.async(){
任何帮助表示赞赏。