Pedometeris one of the iOS feature which can measure, track, calculate distance. It can calculate and count the steps for walking, staircase, heart rate calculation, orientation, rotation, and altitude of the person.
Pedometer measures mainly all accelerometer and gyroscope. Which helps to identify many things. Core motion is core library that is used to be used to calculate various properties of accelerometer and gyroscope.
This library is designed in such a way that it will be fully supported by apple hardware because whatever calculated by code it depends on hardware also. Both hardware and software communicate with each other provide the appropriate data to the users.
Use of Library
CMPedometer:- It will capture the data with an inbuilt motion sensor in the device and shared in the software system.
CMPedometerData:- It is supported by a hardware device that detects the step counting overrunning, walking and moving. Provide data from hardware to software. It validates and captures the moving data from hardware in iOS devices.
CMPedometerEvent:- iOS device monitors the distance moved by users step
CMStepCounter:- iOS has the capability to count the steps taken by user’s but it is possible only when user carry the device with
1. Step count will be done in the view will appear where calculation will be done with time and date
override funcviewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
guard let startDate = startDate else { return }
pedometerStepsCountUpdate(startDate: startDate)
}
2. Pedometer will start updating the data the step count and motion count
@objcPublicfuncdidTapStartButton() {
pedometerStartUpdating = !pedometerStartUpdating
pedometerStartUpdating ? (pedometerStart()) : (pedometerStop())
}
3. Authorization needs to provide from app side where user will get popup message to confirm the
PublicfuncpedometerStart() {
pedometerAuthorizationState()
pedometerUpdate()
}
4. Pedometer can be stopped and start from the app side to reset the settings from the app.
PublicfuncpedometerStop() {
stopUpdating()
}
5. Pedometer can be updated from the app side where activity indicator will be running over the code
PublicfuncpedometerUpdate() {
if CMMotionActivityManager.isActivityAvailable() {
startTrackingActivityType()
} else {
activityTypeLabel.text = "Pedometer available"
}
if CMPedometer.isStepCountingAvailable() {
startCountingSteps()
} else {
stepsCountLabel.text = "Pedometer available"
}
}
6. Pedometer authorization is denied or approved from the app side where pedometer can be authorized.
PublicfuncpedometerAuthorizationState() {
switch CMMotionActivityManager.authorizationStatus() {
case CMAuthorizationStatus.denied:
pedometerStop()
activityTypeLabel.text = "Pedometer available"
stepsCountLabel.text = "Pedometer available"
default:break
}
}
7. Pedometer stop updating the step count and reset the event activity.
PublicfuncstopUpdating() {
activityManager.stopActivityUpdates()
pedometer.stopUpdates()
pedometer.stopEventUpdates()
}
8. Handle error to find the pedometer activity.
Publicfunc on(error: Error) {
//handle error
}
9. Pedometer Steps Count can be Updated with hardware to software so that it will reflect the count in the UI.
PublicfuncpedometerStepsCountUpdate(startDate: Date) {
pedometer.queryPedometerData(from: startDate, to: Date()) {
[weak self] pedometerData, error in
if let error = error {
self?.on(error: error)
} else if let pedometerData = pedometerData {
DispatchQueue.main.async {
self?.stepsCountLabel.text = String(describing: pedometerData.numberOfSteps)
}
}
}
}
10. Pedometer tracking activity calculated with moving, walking, running and Stationary by step count.
PublicfuncstartTrackingActivityType() {
activityManager.startActivityUpdates(to: OperationQueue.main) {
[weak self] (activity: CMMotionActivity?) in
guard let activity = activity else { return }
DispatchQueue.main.async {
if activity.walking {
self?.activityTypeLabel.text = "Pedometer Walking"
} else if activity.stationary {
self?.activityTypeLabel.text = "Pedometer Stationary"
} else if activity.running {
self?.activityTypeLabel.text = "Pedometer Running"
} else if activity.automotive {
self?.activityTypeLabel.text = "Pedometer Automotive"
}
}
}
}
11. Pedometer step can be calculated and counting with the help android application development services.
PublicfuncstartCountingSteps() {
pedometer.startUpdates(from: Date()) {
[weak self] pedometerData, error in
guard let pedometerData = pedometerData, error == nil else { return }
DispatchQueue.main.async {
self?.stepsCountLabel.text = pedometerData.numberOfSteps.stringValue
}
}
}
Tuesday November 12, 2024
Tuesday November 5, 2024
Monday October 21, 2024
Monday October 7, 2024
Friday September 20, 2024
Tuesday August 27, 2024
Monday August 26, 2024
Thursday August 22, 2024
Tuesday June 11, 2024
Thursday May 16, 2024