Latest 2.0.2
Homepage https://github.com/AckeeCZ/ReactiveLocation
License MIT
Platforms ios 8.0
Dependencies ReactiveSwift
Authors


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.

Latest podspec

{
    "name": "ReactiveLocation",
    "version": "2.0.2",
    "summary": "Simple yet powerful wrapper of CLLocationManager for ReactiveCocoa",
    "description": "Simple yet powerful wrapper of CLLocationManager for ReactiveCocoa. With support of requestim permissions and obtaiining user's location. Heading, Regions and Visits.",
    "homepage": "https://github.com/AckeeCZ/ReactiveLocation",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ackee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AckeeCZ/ReactiveLocation.git",
        "tag": "2.0.2"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "ReactiveLocation/Classes/**/*",
    "dependencies": {
        "ReactiveSwift": [
            "~> 1.0"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This