Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase pedometer initial response on iOS

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()
like image 809
Nermin Sehic Avatar asked Oct 20 '22 14:10

Nermin Sehic


1 Answers

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.

like image 52
Deveram Avatar answered Oct 22 '22 04:10

Deveram