Position
is a lightweight and efficient location positioning library for iOS.
Features | |
---|---|
☄ | “one shot” customizable location requests |
🌌 | distance and time-based location filtering |
🛰 | location tracking support |
📊 | automatically manage energy resources based on tracking |
🔒 | permission check and response support |
📍 | vCard location creation |
🌁 | automatic low-power location tracking adjustment when backgrounded setting |
🔋 | automatic low-power location tracking adjustment from battery monitoring setting |
🔭 | multiple component observer-based architecture |
Need a different version of Swift?
5.0
- Target your Podfile to the latest release or master4.2
- Target your Podfile to theswift4.2
branch
Position
is available for installation using the Cocoa dependency manager CocoaPods. Alternatively, you can simply copy the Position
source files into your Xcode project.
# CocoaPods
pod "Position", "~> 0.7.0"
# Carthage
github "piemonte/Position" ~> 0.7.0
# SwiftPM
let package = Package(
dependencies: [
.Package(url: "https://github.com/piemonte/Position", majorVersion: 0)
]
)
The sample project provides an example of how to integrate Position
, otherwise you can follow these steps.
Ensure your app’s Info.plist
file includes both a location usage description, required device capability “location-services”, and required background mode (if necessary).
See sample project for examples too.
Import the file and setup your component to be a PositionObserver, if you’d like it to be a delegate.
import Position
class ViewController: UIViewController, PositionObserver {
// ...
Have the component add itself as an observer and configure the appropriate settings.
override func viewDidLoad() {
super.viewDidLoad()
// ...
Position.shared.addObserver(self)
Position.shared.distanceFilter = 20
if Position.shared.locationServicesStatus == .allowedWhenInUse ||
Position.shared.locationServicesStatus == .allowedAlways {
Position.shared.performOneShotLocationUpdate(withDesiredAccuracy: 250) { (location, error) -> () in
print(location, error)
}
} else {
// request permissions based on the type of location support required.
Position.shared.requestWhenInUseLocationAuthorization()
// Position.shared.requestAlwaysLocationAuthorization()
}
}
Observe delegation, if necessary.
func position(position: Position, didChangeLocationAuthorizationStatus status: LocationAuthorizationStatus) {
// location authorization did change, often this may even be triggered on application resume if the user updated settings
}
Remember when creating location-based apps, respect the privacy of your users and be responsible for how you use their location. This is especially true if your application requires location permission kCLAuthorizationStatusAuthorizedAlways
.
To share a location using a vCard, simply call the vCard function on any location object instance.
let fileURL = location.vCard()
You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.
- Need help? Use Stack Overflow with the tag ‘position-swift’.
- Questions? Use Stack Overflow with the tag ‘position-swift’.
- Found a bug? Open an issue.
- Feature idea? Open an issue.
- Want to contribute? Submit a pull request.
Position is available under the MIT license, see the LICENSE file for more information.