Git Product home page Git Product logo

asynclocationkit's Introduction

AsyncLocationKit

Swift Package Manager Swift Platforms

Wrapper for Apple CoreLocation framework with new Concurency Model. No more delegate pattern or completion blocks.

Install


SPM
dependencies: [
    .package(url: "https://github.com/AsyncSwift/AsyncLocationKit.git", .upToNextMinor(from: "1.6.1"))
]

Cocoapods

pod 'AsyncLocationKit', :git => 'https://github.com/AsyncSwift/AsyncLocationKit.git', :tag => '1.6.1'

⚠️ Initialize AsyncLocationManager only synchronously on MainThread

import AsyncLocationKit

let asyncLocationManager = AsyncLocationManager(desiredAccuracy: .bestAccuracy)

Task {
    let permission = await self.asyncLocationManager.requestAuthorizationWhenInUse() //returns CLAuthorizationStatus
}

You can use all methods from Apple CLLocationManager.

Task {
    let coordinate = try await asyncLocationManager.requestLocation() //Request user location once
}

Start monitoring update of user location with AsyncStream.

Task {
    for await locationUpdateEvent in await asyncLocationManager.startUpdatingLocation() {
        switch locationUpdateEvent {
        case .didUpdateLocations(let locations):
            // do something
        case .didFailWith(let error):
            // do something
        case .didPaused, .didResume: 
            break
        }
    }
}

If Task was canceled, Stream finished automaticaly.

asynclocationkit's People

Contributors

gre4ixin avatar andrewdodd42 avatar humblehacker avatar romanpodymov avatar elyesder avatar tgmpaul avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.