I'm struggling totally to get CMPedometer to return any step data. However Iconfigure I get Error Domain=CMErrorDomain Code=103 "The operation couldn’t be completed. (CMErrorDomain error 103.)"
I'm using swift and have broken down the queryPedometerDataFromDate
query to be as simple as possible.
let pedometer = CMPedometer()
let fromDateString = "2015-01-22"
let toDateString = "2015-01-23"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "YYYY-MM-DD"
let fromDate = dateFormatter.dateFromString(fromDateString)
let toDate = dateFormatter.dateFromString(toDateString)
pedometer.queryPedometerDataFromDate(fromDate, toDate: toDate) { (data:CMPedometerData!, error:NSError!) -> Void in
if error == nil {
println(data)
} else {
println(error)
}
}
I've enabled motion detection for my app, and have no problem getting similar data out of HealthKit.
I must be missing something simple, but I can't see what it is!
Ok, so after another day of research. You have to have the CMPedometer
object as a global variable for your class. If it's defined as a local variable like in the question it won't work. Simply adding let pedometer = CDPedometer()
at the class level will fix this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With