Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yoman07/swiftbackgroundlocation
Efficient and Easy Location Background Monitoring in Swift
https://github.com/yoman07/swiftbackgroundlocation
background cllregion corelocation geofencing location mapkit region swift terminated
Last synced: 5 days ago
JSON representation
Efficient and Easy Location Background Monitoring in Swift
- Host: GitHub
- URL: https://github.com/yoman07/swiftbackgroundlocation
- Owner: yoman07
- License: mit
- Created: 2017-03-05T12:57:27.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-21T10:45:56.000Z (about 7 years ago)
- Last Synced: 2025-01-01T23:46:34.009Z (5 days ago)
- Topics: background, cllregion, corelocation, geofencing, location, mapkit, region, swift, terminated
- Language: Swift
- Size: 193 KB
- Stars: 73
- Watchers: 4
- Forks: 21
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftBackgroundLocation
[![CI Status](http://img.shields.io/travis/yoman07/SwiftBackgroundLocation.svg?style=flat)](https://travis-ci.org/yoman07/SwiftBackgroundLocation)
[![Version](https://img.shields.io/cocoapods/v/SwiftBackgroundLocation.svg?style=flat)](http://cocoapods.org/pods/SwiftBackgroundLocation)
[![License](https://img.shields.io/cocoapods/l/SwiftBackgroundLocation.svg?style=flat)](http://cocoapods.org/pods/SwiftBackgroundLocation)
[![Platform](https://img.shields.io/cocoapods/p/SwiftBackgroundLocation.svg?style=flat)](http://cocoapods.org/pods/SwiftBackgroundLocation)SwiftBackground is the right choice to work easily and efficiently with Location Manager when your app is terminated or killed. It's based on region monitoring. Demo how it works (blue is normal tracking, red line is region based tracking):
![](https://media.giphy.com/media/xUA7biAFYmwE8IKcDe/source.gif)
## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first.
Just add in your app delegate for background location:
```swift
var backgroundLocationManager = BackgroundLocationManager()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
backgroundLocationManager.startBackground() { result in
if case let .Success(location) = result {
LocationLogger().writeLocationToFile(location: location)
}
}return true
}
```You can set up radius for background location:
```swift
let regionConfig = RegionConfig(regionRadius: 25.0)
var backgroundLocationManager = BackgroundLocationManager(regionConfig: regionConfig)
```Getting permission (`.always` or `.whenInUse`) for location tracking:
```swift
locationManager.manager(for: .always, completion: { result in
if case let .Success(manager) = result {
}})
```Location tracking with listener:
```swift
locationManager.manager(for: .always, completion: { result in
if case let .Success(manager) = result {
manager.startUpdatingLocation(isHeadingEnabled: true) { [weak self] result in
if case let .Success(locationHeading) = result, let location = locationHeading.location {
self?.updateLocation(location: location)
}
}
}})
```Getting heading needs additional hardware and hence wont work on simulator.
## Requirements
## Installation
SwiftBackgroundLocation is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "SwiftBackgroundLocation"
```You must add NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key to your project’s Info.plist containing the message to be displayed to the user at the prompt. If you need always location, you should add both.
```
NSLocationAlwaysUsageDescription
$(PRODUCT_NAME) needs location always usage for recording in background.
``````
NSLocationWhenInUseUsageDescription
$(PRODUCT_NAME) needs location when in use for recording in foreground.
```The user will not be prompted unless one of these are added to the Info.plist.
## Author
yoman07, [email protected]
## License
SwiftBackgroundLocation is available under the MIT license. See the LICENSE file for more info.
### Contact & Questions
If you have any questions, fell free to send me a mail.
You can also fork this project, or open an issue### Contributions
SwiftBackgroundLocation is currently lead by:- Roman Barzyczak (`GitHub `__)
with contributions from:
- `Andrew Sowers `__