I'm building an indoor location based app with iBeacons however I'm using a lot of iPhone sensors in order to get an accurate movement representation (speed, direction etc.) I'm currently stuck with CoreMotion pedometer and it's step counting property. I have a piece of code that simply counts the steps and prints them in a label and I've noticed that it takes around 10 steps before the device registers my movement and then updates the label every third or fourth step. These updates in the "walking" state are fine but I'm interested to know if it is possible to speed up the initial response and transition from stationary -> walking and instead of 10 reduce it to 5 which would be acceptable. This is the code for counting steps:
if(CMPedometer.isStepCountingAvailable()){
self.pedoMeter.queryPedometerDataFromDate(NSDate(), toDate: NSDate()) { (data : CMPedometerData!, error) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil){
self.steps.text = "\(data.numberOfSteps)"
}
})
}
self.pedoMeter.startPedometerUpdatesFromDate(NSDate()) { (data: CMPedometerData!, error) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil){
self.steps.text = "\(data.numberOfSteps)"
}
})
}
}
}
I have also increased the update interval to maximum
manager.deviceMotionUpdateInterval = 0
And these are the classes that I'm using
let activityManager = CMMotionActivityManager()
let manager = CMMotionManager()
let pedoMeter = CMPedometer()
You can't do that because Apple have a limit on the update interval based on the device you're using. The biggest interval you can have is 0.01 seconds. Pedometers usually work better on longer distances, you should use accelerometer data for that.
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