Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

SwiftadvancedmobileAI generated

Location-Based Fitness Tracker with HealthKit

Build an iPhone app that records outdoor runs. It tracks your route with GPS, keeps recording while the phone is locked, reads your heart rate from HealthKit, draws the route on a map, and saves the finished run as a workout in Apple Health. The main screen has a Start/Stop button and live stats (time, distance, pace); after a run you see a summary with the route on a map. You'll learn how to request and handle location and HealthKit permissions, keep location updates running in the background, draw map overlays in SwiftUI, and compute distance, pace and calories from raw data. You need a Mac with Xcode, and a physical iPhone for the final step, since background GPS and heart-rate data can't be fully tested in the simulator.

Estimate
~17.5h
Steps
8
Completed by
0
Proposed by
codeseed.app

SwiftUI · CoreLocation · HealthKit · MapKit

Project roadmap

  1. 01

    Set up the project and permissions

    ~1.5h

    Create a SwiftUI iOS app. Enable the HealthKit capability and the Background Modes capability with Location updates checked. Add these Info.plist keys, each with a sentence explaining why the app needs it: NSLocationWhenInUseUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSHealthShareUsageDescription and NSHealthUpdateUsageDescription. Done when: the app builds, and both capabilities plus all four Info.plist keys are present.

  2. 02

    Track location during a run

    ~3h

    Create a LocationTracker class (@Observable or ObservableObject) that wraps CLLocationManager. It requests Always authorization, sets allowsBackgroundLocationUpdates to true and pausesLocationUpdatesAutomatically to false, and exposes start() and stop(). While running, it appends each new CLLocation to a list, ignoring points with a horizontalAccuracy worse than 20 meters. Done when: start() collects filtered points, stop() ends it, and the list is observable from SwiftUI.

  3. 03

    Compute distance, pace and duration

    ~2h

    Write pure functions (no location manager, no UI) that take the recorded points and return the total distance in km (the sum of distance(from:) between consecutive points), the elapsed time, and the average pace in minutes per km. Fewer than two points means zero distance, and pace is nil when the distance is zero. Done when: these functions live in their own file and return correct values for a hand-made list of points.

  4. 04

    Build the live run screen

    ~2h

    Build the main screen: a Start/Stop button and live labels for elapsed time (updating every second), distance in km with two decimals, and average pace formatted as m:ss /km. Disable Start while a run is in progress. If location permission is denied, show a clear message with a button that opens the app's page in Settings. Done when: starting a run updates the stats live, and stopping it freezes them.

  5. 05

    Read heart rate from HealthKit

    ~3h

    Create a HealthManager that requests read access to heart rate and write access to workouts and active energy. During a run, start an HKAnchoredObjectQuery for heart-rate samples from the run's start date and publish the latest value in bpm. Show it on the run screen, or a dash when there's no data (for example, no Apple Watch paired). Done when: authorization is requested once, and the latest heart-rate sample appears on screen during a run.

  6. 06

    Show the route on a map

    ~2h

    When a run ends, open a summary screen with a SwiftUI Map that draws the recorded route as a MapPolyline, with markers at the start and finish, and the camera fitted to the whole route. Below the map, show total distance, total time, average pace and average heart rate. Done when: finishing a run opens the summary with the full route visible on the map.

  7. 07

    Save the workout to Apple Health

    ~2h

    Estimate calories burned as distance in km × body weight in kg (read from HealthKit, or 70 kg if unavailable). Save the run as a running HKWorkout with HKWorkoutBuilder, including the start and end dates, total distance and the calorie estimate. Show a confirmation when saving succeeds and a readable error when it fails. Done when: a finished run appears as a running workout in the Health app.

  8. 08

    Test on a real device

    ~2h

    Add unit tests for the functions from step 3, including the empty-route and single-point cases. Then run the app on a physical iPhone: start a run, lock the screen, walk for a few minutes, and check that the route kept recording while locked. Write down what you tested and the result in a TESTING.md file at the root of the repo. Done when: the unit tests pass and TESTING.md describes the device test and its outcome.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~17.5h · 8 steps

Tech stack

SwiftUICoreLocationHealthKitMapKit