Giter Site home page Giter Site logo

apscheduledlocationmanager's Introduction

APScheduledLocationManager

license MIT

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)

Requirements

  • Xcode 8
  • Swift 3.0
  • iOS 9.0+

Installation

CocoaPods. Please use the latest CocoaPods as this framework is using Swift 3
use_frameworks!

pod 'APScheduledLocationManager'

Usage

1. Configure Xcode project

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.

2. Import APScheduledLocationManager and CoreLocation
import APScheduledLocationManager
import CoreLocation
3. Create instance of APScheduledLocationManager
let manager = APScheduledLocationManager(delegate: self)

If you want control over more of the options you can do the following:

let manager = APSScheduledLocationManager(delegate: self, desiredAccuracy: kCLLocationAccuracyNearestTenMeters, distanceFilter: kCLDistanceFilterNone, pausesLocationUpdatesAutomatically: true)

The defaults are:

  • desiredAccuracy: kCLLocationAccuracyBest
  • distanceFilter: kCLDistanceFilterNone
  • pausesLocationUpdatesAutomatically: false
4. Confirm to APScheduledLocationManagerDelegate
func scheduledLocationManager(_ manager: APScheduledLocationManager, didFailWithError error: Error){

}

func scheduledLocationManager(_ manager: APScheduledLocationManager, didUpdateLocations locations: [CLLocation]) {

}

func scheduledLocationManager(_ manager: APScheduledLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {

}

func locationManagerDidPauseLocationUpdates(_ manager: APScheduledLocationManager) {

}

func locationManagerDidResumeLocationUpdates(_ manager: APScheduledLocationManager) {

}
5. Request authorized always permission

You can use requestAlwaysAuthorization helper method of APScheduledLocationManager or your own implementation.

6. Start location manager when permission is granted
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 overwritten
  • acceptableLocationAccuracy: CLLocationAccuracy - the location manager will wait till locations with desired accuracy are retrieved.
7. To stop location manager call stopLocationManager

Example

See an example app ScheduledLocationExample in the repository

Note, if you test on a stimulater edit scheme and set default location.

License

APScheduledLocationManager is released under an MIT License. See LICENSE for details.

apscheduledlocationmanager's People

Contributors

paleksandrs avatar calvinalvin avatar huguesbr avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.