A wrapper on the CoreLocation framework replacing the delegate pattern with Swift concurrency

Overview

swift-locations

A wrapper on the CoreLocation framework replacing the delegate pattern with Swift concurrency.

Overview

CoreLocation reports a device's location, altitude and orientation from on-device components.

Availability

  • iOS 13.0+
  • iPadOS 13.0+
  • macCatalyst 15.0+
  • macOS 10.15+
  • watchOS 6.0+

Installation

The Swift Package Manager is a tool for managing the distribution of Swift code and is integrated into the swift compiler.

  1. Add the package to the dependencies in your Package.swift file.

    let package: Package = .init(
        ...
        dependencies: [
            .package(url: "https://github.com/alexandrehsaad/swift-locations.git", branch: "main")
        ],
        ...
    )
  2. Add the package as a dependency on your target in your Package.swift file.

    let package: Package = .init(
        ...
        targets: [
            .target(name: "MyTarget", dependencies: [
                .product(name: "Locations", package: "swift-locations")
            ]),
        ],
        ...
    )

Demonstration

  1. Import the package in your source code.

    import Locations
  2. Initiate the manager with your desired accuracy.

    let manager: LocationManager = .init(accuracy: .tenMetres)
  3. Request the user’s permission to use location services and do something with the asynchronous value you receive. You can not show to the user an authorization dialog twice, but you can show the steps to change the permission from Settings.

    do {
        let status: AuthorizationStatus = try await manager.requestAlwaysAuthorization()
    	// Do something with the status.
        print(status)
    } catch let error {
        // Do something with the error.
        print(error)
    }
  4. Subscribe to the locater and do something with the asynchronous stream of values you receive. The return type is CLLocation from the CoreLocation framework.

    do {
        let stream: AsyncStream = try manager.subscribeToLocater()
        for await data in stream {
            // Do something with the data.
            print(data)
        }
    } catch let error {
        // Do something with the error.
        print(error)
    }
  5. Unsubscribe from the locater.

    manager.unsubscribeFromLocater()

Troubleshooting common errors

Your app must include usage description keys in its Info.plist file for the types of data it needs. Failure to include these keys cause the app to crash. To access location data specifically, it must include either NSLocationWhenInUseUsageDescription or NSLocationAlwaysAndWhenInUseUsageDescription.

Documentation

You can read more about this package by visiting the documentation page.

Roadmap

You can use this framework to track large or small changes in the user's current location with a configurable degree of accuracy. It could be extended to support region monitoring, beacon ranging and compass headings.

Contribution

Contributions are what makes the open source community such an amazing place to learn, inspire, and create. If you wish to contribute and be part of this project, please fork the repository and create a pull request.

  1. Fork the repository
  2. Create your feature branch git checkout -b NewFeature
  3. Commit your changes git commit -m 'Added a new feature'
  4. Push to your branch git push origin NewFeature
  5. Open a pull request

Reporting a bug

If you find a bug, please create an issue.

Contacting the maintainers

The current code owner of this repository is Alex (@alexandrehsaad). If you want to share your thoughts or feedback on how to improve this repository, you can contact him by writing an email to alexandresaad at icloud dot com.

Supporting this repository

If this repository has been useful to you in some way, show your support by starring it.

License

Distributed under Apache License v2.0 with Runtime Library Exception. See the LICENSE.txt file for more information.

You might also like...
A wrapper around UICollectionViewController enabling a declarative API around it's delegate methods using protocols.

Thunder Collection Thunder Collection is a useful framework which enables quick and easy creation of collection views in iOS using a declarative appro

This to learn such as : Add Target , NSNotification Center Send/Get Data , Observer Override , resize Data By Byte , UIImagePicker Delegate , UIAlert Handle , Top ViewController , Get pickerController

Technicalisto How to Create UIButton Class to Pick Data Image Purpose Learn this topics With exact Task Add Target NSNotification Center Send/Get Data

 Delegate Prinzip
Delegate Prinzip

DelegatePrinzip change the house color, selecting the right key.

QR code detector. Simple usage, you can get recognition results via delegate or callback.

SPQRCode QR code detector. Simple usage, you can get recognition results via delegate or callback. Installation Swift Package Manager CocoaPods Manual

AsyncLocationKit - Async/await CoreLocation With Swift

AsyncLocationKit Wrapper for Apple CoreLocation framework with new Concurency Mo

ARKit + CoreLocation: Combines the high accuracy of AR with the scale of GPS data.
ARKit + CoreLocation: Combines the high accuracy of AR with the scale of GPS data.

ARKit: Uses camera and motion data to map out the local world as you move around. CoreLocation: Uses wifi and GPS data to determine your global locati

🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Example app using MessagesUI + CoreLocation + MapKit

iOS Example MapKit App Ejemplo de código de una aplicación de mapas usando MessagesUI, MapKit y CoreLocation Built using XCode 13.0 (Swift 5) ¿Cómo ej

🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring
🛰 CoreLocation Made Easy - Efficient & Easy Location Tracker, IP Location, Gecoder, Geofence, Autocomplete, Beacon Ranging, Broadcaster and Visits Monitoring

Location Manager Made Easy SwiftLocation is a lightweight Swift Library that provides an easy way to work with location-related functionalities. No mo

Enumerate Location Services using CoreLocation API on macOS
Enumerate Location Services using CoreLocation API on macOS

SwiftLiverpool Description This tool leverages the CoreLocation API on macOS to enumerate Location Services data. You need to enable "Location Service

Weather - Weather app to practice using CoreLocation, fetching data from openweathermap.org API, JSON decoding, applying day\night appearance WeatherSampleApp - Weather Sample app with SwiftUI consuming data from OpenWeather and using CoreLocation
WeatherSampleApp - Weather Sample app with SwiftUI consuming data from OpenWeather and using CoreLocation

WeatherSampleApp Weather application using SwiftUI Uses data provided by https:/

Using CoreLocation and MapKit Together
Using CoreLocation and MapKit Together

Using_CoreLocation_and_MapKit_Together CoreLocation and Mapkit were used togethe

⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading
⚡️ Fast async task based Swift framework with focus on type safety, concurrency and multi threading

Our apps constantly do work. The faster you react to user input and produce an output, the more likely is that the user will continue to use your appl

BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Unidirectional flow implemented using the latest Swift Generics and Swift Concurrency features.

swift-unidirectional-flow Unidirectional flow implemented using the latest Swift Generics and Swift Concurrency features. struct SearchState: Equatabl

A simple swift package that provides a Swift Concurrency equivalent to `@Published`.

AsyncValue This is a simple package that provides a convenience property wrapper around AsyncStream that behaves almost identically to @Published. Ins

A complete set of primitives for concurrency and reactive programming on Swift
A complete set of primitives for concurrency and reactive programming on Swift

A complete set of primitives for concurrency and reactive programming on Swift 1.4.0 is the latest and greatest, but only for Swift 4.2 and 5.0 use 1.

Releases(0.1.0)
Owner
Alexandre H. Saad
Student @ Apple Developer Academy | Software Engineer | Graphic Designer | iOS | Swift | UI/UX
Alexandre H. Saad
Enumerate Location Services using CoreLocation API on macOS

SwiftLiverpool Description This tool leverages the CoreLocation API on macOS to enumerate Location Services data. You need to enable "Location Service

Justin Bui 4 Aug 20, 2022
A Swift wrapper for forward and reverse geocoding of OpenStreetMap data

Nominatim NominatimKit is a Swift wrapper for forward and reverse geocoding of OpenStreetMap data. Why? Geocoding location data on iOS requires the us

Josef Moser 53 Feb 5, 2022
Open-source iOS application written to explore Swift in its early days

Cepp iOS application written in Swift. Icon by: Rodrigo Nascimento (tks :D) IMPORTANT: *This project uses CocoaPods as the dependency manager, make su

Filipe Alvarenga 14 Sep 12, 2022
Contains the swift rewrite of Find My Bus NJ iOS App

FIND MY BUS NJ 2 An app for tracking NJ Transit bus times. Dependancies Alamofire SwiftyJSON PKHUD Fabric Getting started Install fastlane and imagema

null 44 Dec 10, 2022
The most power-efficient and lightweight iOS location manager for Swift and ObjC

IngeoSDK for iOS Overview IngeoSDK is a power-efficient location manager for iOS (Swift and Objective-C), which extends and improves CoreLocation. It

IngeoSDK 99 Feb 28, 2022
Location Weather Demo With Swift

LocationWeatherDemo Здравствуйте! Для того что бы проект корректно работал установите pod's. О проекте: 1) На первой странице можно увидеть погоду в л

German Khodyrev 0 Dec 8, 2021
GoogleMapsApp - Google Maps App With Swift

googleMapsApp Тестовое задание Current location: Import points from servers:

Fedot Evseev 0 Jan 11, 2022
A silly CLI for replacing macosx.internal SDK settings in .xcodeproj files with macosx

fix-macos-internal-sdk A silly CLI for replacing macosx.internal SDK settings in .xcodeproj files with macosx.

Keith Smiley 14 Dec 6, 2022
A meta library to provide a better `Delegate` pattern.

Delegate A meta library to provide a better Delegate pattern described here and here. Usage Instead of a regular Apple's protocol-delegate pattern, us

Wei Wang 67 Dec 23, 2022
Cryptocurrency price checker, build with UIKit and MVC + Delegate pattern.

Coin Check Cryptocurrency price checker. The app fetch from CoinAPI.io the latest coin prices, build with UIKit and MVC + Delegate pattern. Features S

Anibal Ventura 0 Jan 10, 2022