SpeedManagerModule

0.04

Simple Speedometer class to iOS and WatchOS.
ezefranca/SpeedManagerModule

What's New

0.04

2023-10-31T14:40:32Z

What's Changed

  • return speedAccuracy, do not return negative speed by @billypchan in #1

New Contributors

Full Changelog: 0.0.3...0.04

SPM compatible github workflow License Twitter

SpeedManagerModule

Simple Speedometer class to iOS and WatchOS.

Measure the speed using an iPhone or Apple Watch.

SpeedManagerModule

Motivation

I like to measure my speed inside trains and buses. When I was searching for a speedometer app, the majority of them were ugly, with tons of ads. I was searching for an Apple Watch Speedometer with complications, iOS App with Widgets and did not found. Because of that I decided to create my own app. First thing was measure speed using CLLocationManager.

Installation

The Swift Package Manager is the easiest way to install and manage SpeedManagerModule as a dependecy. Simply add SpeedManagerModule to your dependencies in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/ezefranca/SpeedManagerModule.git")
]

Update Info.plist

Add the correct permission descriptions

    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>

Add the background location updates in xcode

Or add the info to the Info.plist

    <key>UIBackgroundModes</key>
    <array>
        <string>location</string>
    </array>

Usage example

@StateObject

import SwiftUI

struct ContentView: View {
    
    @StateObject var speedManager = SpeedManager(.kilometersPerHour)
    
    var body: some View {
        VStack {
            switch speedManager.authorizationStatus {
            case .authorized:
                Text("Your current speed is:")
                Text("\(speedManager.speed)")
                Text("km/h")
            default:
                Spacer()
            }
        }
    }
}

Using Delegates

import UIKit

class SpeedViewController: UIViewController {

    var speedManager = SpeedManager(.kilometersPerHour)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.speedManager.delegate = self
        self.speedManager.startUpdatingSpeed()
    }
}

extension SpeedViewController: SpeedManagerDelegate {
    
    func speedManager(_ manager: SpeedManager, didUpdateSpeed speed: Double) {
    }
    
    func speedManager(_ manager: SpeedManager, didFailWithError error: Error) {
    }
}

Changing Unit

Just choose the unit during the class init.

    var speedManagerKmh = SpeedManager(.kilometersPerHour)
    var speedManagerMs = SpeedManager(.meterPerSecond)
    var speedManagerMph = SpeedManager(.milesPerHour)

Demo

Check the Demo folder to see it in action.

demo.mov

Meta

@ezefranca – @ezefranca

Distributed under the MIT license. See LICENSE for more information.

https://github.com/ezefranca/SpeedManagerModule

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Apr 19 2024 06:53:57 GMT-0900 (Hawaii-Aleutian Daylight Time)