I am currently developing app that counts the Steps, and for that I am using the pedometer. I am not sure of how frequent pedometer provides updates, in my case it provides update around 3 second. There is nothing mentioned about frequency of Data in Official documentation of Apple or Any ways to set the Frequency.
Application is in Both iOS and WatchOS plateform
To achieve data i have tried following things:
- With startUpdates(from: Date)
pedometer.startUpdates(from: Date()) { [weak self] pedometerData, error in
guard let data = pedometerData, error == nil else { return }
DispatchQueue.main.async {
self?.stepCount = data.numberOfSteps.intValue
}
}
- With queryPedometerData()
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
self?.fetchPedometerData()
}
private func fetchPedometerData() {
pedometer.queryPedometerData(from: Date().addingTimeInterval(-1), to: Date()) { [weak self] pedometerData, error in
guard let data = pedometerData, error == nil else { return }
DispatchQueue.main.async {
self?.stepCount = data.numberOfSteps.intValue
}
}
}
I have done this both implementation but Not getting desired results.
I want data every second, Could it be possible ? Any help or leads would really helpful
Thank You :)