LocationMonitor is a simple wrapper class written around CLLocationManager
and CLLocationManagerDelegate
to make requesting permissions and getting access to the user's current location quick and easy.
- Trigger permission prompt when suits you best
- Get user's current location in one call
- Customisable location update timeout
- Supports multiple listeners to receive location updates independently
- Per location listener update filter
Ensure you add one of the following keys with an associated string to your Info.plist file
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
- iOS 9.3+
- Xcode 8.0+
- Swift 3.0+
LocationManager.shared.requestPermission()
let (authorized, status) = LocationManager.shared.isAuthorized()
Where authorized is a Bool
and status is a value of CLAuthorizationStatus
do {
var stopUpdating = try LocationManager.shared.startUpdatingLocation { location, error, stopUdating in
print(location) // Do something with return location
stopUdating() // Stop receiving location updates on this listener
}
} catch {
print(error)
}
The location update callback contains 3 parameters an optional CLLocation
object, an optional error and a function that will stop updates on this listener.
do {
try LocationManager.shared.startUpdatingLocation({ location -> Bool in
// Do some specific update filter block here
return true
}, locationUpdate: { location, error, stopUdating in
stopUdating()
})
} catch {
print(error)
}
LocationManager.shared.accuracy = CLLocationAccuracy(10)
LocationManager.shared.distance = CLLocationDistance(100)
LocationManager.shared.timeout = 60
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate LocationMonitor into your Xcode project using Carthage, specify it in your Cartfile:
github "niceagency/LocationMonitor"
Run carthage update
to build the framework and drag the built LocationMonitor.framework into your Xcode project.
Please review the CLLocationManager documentation for more information.
This library is written in Swift 3.
If you wish to contribute to LocationMonitor please fork the repository and send a pull request or raise an issue within GitHub.
LocationMonitor is released under the MIT license. See LICENSE for details.