Loading ...

Integration of Pedometer in Swift iOS Development

Integration of Pedometer in Swift iOS Development

by — 2 weeks ago in Development 3 min. read

Pedometer Introduction

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.

Pedometer Framework iOS

  • Core Motion
  • Health kit

Use of Library

  • Walking, Moving, and running distance calculation.
  • Heartbeat tracking.
  • Counting steps per day.
  • Data can be kept secure for 6-7 days.
  • Historical data can be maintained for various activities.
  • Finding and Calculate the rotation altitude and acceleration of the device when users are moving from one place to another
  • Motion detection
  • Direction calculation and finding the compass

Perquisite for Pedometer integration

  • Framework added in the build settings Properly
  • Plist file needs to configure properly for settings

pedometer - Integration of Pedometer in Swift iOS Development

  • Important things for Pedometer

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

Code Steps to implementation

1. Step count will be done in the view will appear where calculation will be done with time and date

 override funcviewWillAppear(_ animated: Bool) {  
     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() {  

4. Pedometer can be stopped and start from the app side to reset the settings from the app.

 PublicfuncpedometerStop() {  

5. Pedometer can be updated from the app side where activity indicator will be running over the code

 PublicfuncpedometerUpdate() {  
     if CMMotionActivityManager.isActivityAvailable() {  
     } else {  
 activityTypeLabel.text = "Pedometer available"  
     if CMPedometer.isStepCountingAvailable() {  
     } 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:  
 activityTypeLabel.text = "Pedometer available"  
 stepsCountLabel.text = "Pedometer available"  

7. Pedometer stop updating the step count and reset the event activity.

 PublicfuncstopUpdating() {  

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  

At Netmobility with our experienced and updated android application development services, enterprise mobility management services, we create smarter and robust mobile apps which bring out your business charactersitics in an attractive way for its customers.

  • Top 5 reasons companies are turning to no-code platforms Jul 28, 2020, 3:15 PM
  • What is INSTAGRAM and Why You should use it full guide? Jul 26, 2020, 9:00 AM
  • Integration of Pedometer in Swift iOS Development Jul 26, 2020, 4:14 PM

Sunday August 2, 2020

Monday July 27, 2020

Monday July 27, 2020

Never miss out

Sign up with TNT and get direct story to your inbox.
Facebook Pagelike Widget

Twitter Feeds

Let’s Explore The Various Aspects of Flutter App Development https://www.the-next-tech.com/?p=24969 #flutterappdevelopment #flutterframework #mobileapplicationdevelopmentcompany #technology

Move Your Brick-And-Mortar Business Online (Seamlessly) Using These Tips https://www.the-next-tech.com/?p=24325

Load More...

Related Posts


Say Goodbye to your Software Hassles with No-Code
By: Vivek Goel, Thu August 6, 2020

When you go to work every day, you want to be efficient and productive. You..


How To Become a more Productive — Best Habits Of Highl...
By: Shikha sharma, Sat July 25, 2020

It’s very difficult to know, how to invest your time or would say..


Reliance Jio to launch Made in India 5G Network
By: Richard Gall, Thu July 16, 2020

India’s top telecom operator Reliance Jio on Wednesday declared that the..


Essential Tips for WordPress Beginners
By: Shailendra Kadulkar, Wed July 8, 2020

WordPress is open-source software that helps general people to create their..


Step-by-step Solution to Perform Office 365 Tenant to Office...
By: Venn Torr, Sat July 4, 2020

In this current business scenario, there are many organizations that are moving..


How to Invest in Yourself During Lockdown
By: Alan Jackson, Wed June 24, 2020

Investing in yourself may be the most profitable investment you ever make. It..

Notify of
Inline Feedbacks
View all comments

Copyright © 2018-2020 The Next Tech. All Rights Reserved.