ReactiveCocoa wrapper for CLLocationManager.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
ReactiveLocation.xcodeproj
ReactiveLocation
ReactiveLocationExample
ReactiveLocationTests
.gitignore
.travis.yml
CHANGELOG.md
Cartfile
Cartfile.resolved
LICENSE
README.md
ReactiveLocation.podspec

README.md


Travis branch Version License Platform

ReactiveSwift wrapper for CLLocationManager.

Our wrapper supports almost all operations on CLLocationManager. With factory method you can easily set up manager for your needs. By default we just set the desiredAccuracy on Best. You can even request for users permission with Action. Mocking support for tests via Protocol implementation.

Available methods

static func locationProducer(_ managerFactory: LocationManagerConfigureBlock?) -> SignalProducer<CLLocation, LocationError>
static func singleLocationProducer(_ managerFactory: LocationManagerConfigureBlock?) -> SignalProducer<CLLocation, LocationError>
static func visitProducer(_ managerFactory: LocationManagerConfigureBlock?) -> SignalProducer<CLVisit, LocationError>
static func regionProducer(_ region: CLRegion, managerFactory: LocationManagerConfigureBlock?) -> SignalProducer<RegionEvent, LocationError>
static func headingProducer(_ managerFactory: LocationManagerConfigureBlock?) -> SignalProducer<CLHeading, LocationError>
static var authorizeAction: Action<LocationAuthorizationLevel, LocationAuthorizationLevel, LocationAuthorizationError> { get }

Difference versus location and singleLocation lies in ios9+ implementation of CLLocationManager's method requestLocation which takes care of the unneccesary logic and gets you just one precise location of the user. Producer itself holds strong reference on its own CLLocationManager so as long as Producer/Signal closure is alive so is its manager.

Example Usage

Simply retrieve user's current location

ReactiveLocation.locationProducer().startWithResult {
    switch $0 {
    case let .success(location):
        print(location)
    case let .failure(error):
        print(error)
    }
}

Simply retrieve location over time. With custom manager settings

ReactiveLocation.singleLocationProducer { manager in
    manager.distanceFilter = 1000
    manager.desiredAccuracy = kCLLocationAccuracyBest
    }
    .startWithResult {
        switch $0 {
        case let .success(location):
            print(location)
        case let .failure(error):
            print(error)
        }
}

Request user for WhenInUse permissions with result

ReactiveLocation.authorizeAction.apply(.whenInUse).startWithResult {
    switch $0 {
    case let .success(status):
        print("Current user permission status on WhenInUse is \(status)")
    case let .failure(error):
        print(error)
    }
}

Testing Support

ReactiveLocation conforms to ReactiveLocationService protocol. So if you would like to mock your own location and test functionality you can just Create your own MockImplementation that conforms to this protocol

Example

In progresss

Requirements

ReactiveSwift

Installation

ReactiveLocation is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ReactiveLocation"

Version compatibility

ReactiveLocation requires Xcode 8+ and Swift 3. Older versions are supported in previous versions.

Swift Version ReactiveLocationVersion
3.X master
2.X 1.0

Forking this repository

If you use ReactiveLocation in your projects drop us a tweet at @ackeecz or leave a star here on Github. We would love to hear about it!

Sharing is caring

This tool and repo has been opensourced within our #sharingiscaring action when we have decided to opensource our internal projects

Author

Ackee team

License

ReactiveLocation is available under the MIT license. See the LICENSE file for more info.