Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

New ReactiveLocation #19

Merged
merged 12 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .github/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ DerivedData
# Bundler
.bundle

Carthage
Carthage/Build
Carthage/Checkouts
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ before_install:
before_script:
- carthage bootstrap --platform iOS --cache-builds
before_deploy:
- carthage build --no-skip-current --platform iOS --cache-builds
- carthage archive $FRAMEWORK_NAME
after_deploy:
- pod trunk push
script:
- set -o pipefail && xcodebuild test -scheme ReactiveLocation -destination 'platform=iOS Simulator,name=iPhone XS,OS=12.2' ONLY_ACTIVE_ARCH=NO | xcpretty
- carthage build --no-skip-current --platform iOS --cache-builds
- pod lib lint || pod repo update && pod lib lint
deploy:
provider: releases
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

## master

- completely new version (#19, kudos to @olejnjak)
- automatically asks for permissions
- monitors observers and starts/stops updating location
- fits better in dependency injection as it doesn't use static methods

## 3.2

- fix recursive calls when calling without parameters (#17, kudos to @olejnjak)
Expand Down
1 change: 1 addition & 0 deletions Cartfile.private
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github "ReactiveCocoa/ReactiveCocoa" ~> 9.0
1 change: 1 addition & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
github "ReactiveCocoa/ReactiveCocoa" "9.0.0"
github "ReactiveCocoa/ReactiveSwift" "5.0.0"
github "antitypical/Result" "4.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveSwift.framework
$(SRCROOT)/Carthage/Build/iOS/Result.framework
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveCocoa.framework
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/ReactiveSwift.framework
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Result.framework
95 changes: 26 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,58 @@
![](http://img.ack.ee/default/image/test/ios_reactivelocation_logo.png)
![](.github/images/logo.png)

[![Travis branch](https://img.shields.io/travis/AckeeCZ/ReactiveLocation/master.svg)](https://travis-ci.org/AckeeCZ/ReactiveLocation)
[![Version](https://img.shields.io/cocoapods/v/ReactiveLocation.svg?style=flat)](http://cocoapods.org/pods/ReactiveLocation)
[![License](https://img.shields.io/cocoapods/l/ReactiveLocation.svg?style=flat)](http://cocoapods.org/pods/ReactiveLocation)
[![Platform](https://img.shields.io/cocoapods/p/ReactiveLocation.svg?style=flat)](http://cocoapods.org/pods/ReactiveLocation)

## ReactiveSwift wrapper for CLLocationManager.
## ReactiveSwift wrapper to observe location

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.
Our wrapper automatically asks for permission. It determines what kind of permission your app requires by checking the Info.plist of your app.

### Available methods
```swift
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 }
```
By using our wrapper you can use a single instance of `CLLocationManager` and it will automatically start and stop updating location based on the number of observers so your app doesn't drain device battery unnecessarily.

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

### Example Usage
Simply retrieve user's current location
For example usage you can check our example that is part of this repository.

```swift
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
For simplest cases you are provided a `shared` instance:

```swift
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)
}
ReactiveLocation.shared.locationProducer().startWithValues { location in
print(location)
}
```

Request user for WhenInUse permissions with result
If you need more different setups for your `CLLocationManager` you can create additional instances simply by creating new instances of `ReactiveLocation` and adding your desired setup to the `locationManager` which is provided to you (but it's up to you to make sure that the instance is alive as long as you need it):

```swift
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)
}
let reactiveLocation = ReactiveLocation()
reactiveLocation.locationManager.distanceFilter = 100 // do your custom setup
reactiveLocation.locationProducer().startWithValues {
print($0)
}
// store `reactiveLocation` instance somewhere
```

## 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

## Testing support


## Example

In progresss

## Requirements

ReactiveSwift
All features of `ReactiveLocation` are wrapped into `ReactiveLocationService` protocol so you should use this protocol as dependency inside your project so you're able to inject any testing implementation you like.

## Installation

ReactiveLocation is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
`ReactiveLocation` is available through Carthage so adding it to your Cartfile works just fine.

```ruby
pod "ReactiveLocation"
github "AckeeCZ/ReactiveLocation"
```

### Version compatibility
If you're not familiar with Carthage, we also support Cocoapods.

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

| Swift Version | ReactiveLocationVersion |
| ------------- | ------ |
| 3.X | master |
| 2.X | 1.0 |
```ruby
pod "ReactiveLocation"
```

Well if you're not familiar with any dependency manager, you're free to integrate it manually. 😎 But keep in mind that we depend on `ReactiveSwift`.

## Forking this repository
If you use ReactiveLocation in your projects drop us a tweet at [@ackeecz][1] or leave a star here on Github. We would love to hear about it!
Expand All @@ -111,4 +68,4 @@ This tool and repo has been opensourced within our `#sharingiscaring` action whe

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

[1]: https://twitter.com/AckeeCZ
[1]: https://twitter.com/AckeeCZ
2 changes: 1 addition & 1 deletion ReactiveLocation.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ReactiveLocation'
s.version = '3.2'
s.version = '4.0-beta.1'
s.summary = 'Simple yet powerful wrapper of CLLocationManager for ReactiveCocoa'
s.description = <<-DESC
Simple yet powerful wrapper of CLLocationManager for ReactiveCocoa. With support of requestim permissions and obtaiining user's location. Heading, Regions and Visits.
Expand Down
Loading