Categories
Manuals

The Simple iOS Pedometer Tutorial

This iOS pedometer tutorial will walk you through the process of building a simple iOS app to track your steps. The iOS pedometer is a fairly easy project, and it can be completed in about an hour if you follow these directions carefully. This iOS pedometer tutorial is designed for beginners who are interested in learning how to create their own iOS apps!


To start, open Xcode and create a new project. Select “Single View Application” from iOS > Application in the left menu bar on the top of your screen. Enter whatever you want for Product Name (such as iOS Pedometer).

Finally, click to select Swift for Language under Devices at the top right corner of your screen. Once you have completed these steps, hit Create! The next step will be adding references to all necessary frameworks that we need to import into our iOS app. At this point, make sure that you’re not using any older versions of iOS or Xcode because they may cause problems when compiling later projects.

Now that we have created our iOS app, it is time to add code. In order for the iOS pedometer to work properly, we need a way to calculate and store each step taken while running the application. To do this, you will want to create two methods: one called “currentStepCount” which stores how many steps are already counted in your iOS pedometer data and another method called “calculateNextStepCount”, which calculates what your next step count should be based on whether or not you’ve reached your set goal yet.

To get started inputting these lines of code into ViewController.swift:

public var currentStepCount = 0; 
public func calculateNextStepCount () -> Int { if currentStepCount > goal { return 0 } currentStepCount += self.distanceBetween(startPoint: start, endPoint: finish) + (self.speed * timeSinceLastPulse); 
print("next step count is \(currentStepcount)")} 
public func distanceBetween(start Point: CLLocationCoordinate, end Point: CLLocationCoordinate) -> Double { var vector = [CLLocationDistance]() let dStartLat = start.coordinate!.latitude; 
let dEndLat = end.coordinate!.latitude; let aa = [[dStartLat]] as! [Double]; 
let bb = [[dLEndLat]] as! [Double]; // Find the length of the line connecting the two points 
let length = sphericalLength(dStartLat, dEndLat) or CLLocationDistance // Convert to meters 
let lengthInMeters = length * 0.01; 
vector += [CLLLocitudeDistance]()
} 
public func timeSinceLastPulse () -> Int { return iOS_Pedometer.countDownTime - iOS_Pedometer.lastBeat }

Leave a Reply

Your email address will not be published. Required fields are marked *