Location manager that allows to get background location updates every n seconds with desired location accuracy.
n - range is between 2 - 170 seconds (limited by max allowed background task time)
- Xcode 8
- Swift 3.0
- iOS 9.0+
CocoaPods. Please use the latest CocoaPods as this framework is using Swift 3
use_frameworks!
pod 'APScheduledLocationManager'In target Capabilities enable Background Modes and check Location updates
In Info.plist add NSLocationAlwaysUsageDescription key and value that will specify the reason for your app to access the user’s location information at all times.
import APScheduledLocationManager
import CoreLocationlet manager = APScheduledLocationManager(delegate: self)func scheduledLocationManager(_ manager: APScheduledLocationManager, didFailWithError error: Error){
}
func scheduledLocationManager(_ manager: APScheduledLocationManager, didUpdateLocations locations: [CLLocation]) {
}
func scheduledLocationManager(_ manager: APScheduledLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
}You can use requestAlwaysAuthorization helper method of APScheduledLocationManager or your own implementation.
manager.startUpdatingLocation(interval: 170, acceptableLocationAccuracy: 100)There are 2 options to adjust the location manager:
interval: TimeInterval- interval with which the location will be gathered. The range is between 2 - 170 seconds, lower or higher values will be overwrittenacceptableLocationAccuracy: CLLocationAccuracy- the location manager will wait till locations with desired accuracy are retrieved.
See an example app ScheduledLocationExample in the repository
Note, if you test on a stimulater edit scheme and set default location.
APScheduledLocationManager is released under an MIT License. See LICENSE for details.