<commit_before>//
//  CQZLocationManager.swift
//  CQZLocationManager
//
//  Created by <NAME> on 12/28/15.
//  Copyright © 2015 ecorenetworks. All rights reserved.
//

import UIKit
import CoreLocation

@objc public protocol CQZLocationManagerDelegate:NSObjectProtocol {
    optional func didUpdateLocation(location:CLLocation)
    optional func didChangeAuthorizationStatus(status:CLAuthorizationStatus)
}

public class CQZLocationManager: NSObject {
    //MARK: - Singleton
    public static let sharedLocationManager = CQZLocationManager()
    
    //MARK: - public properties
    public var currentLocation:CLLocation = CLLocation()
    weak public var delegate:CQZLocationManagerDelegate?
    
    //MARK: - public methods
    public func requestAutorization (type type:CQZLocationManagerRequest){
        switch type {
        case CQZLocationManagerRequest.AlwaysAuthorization:
            locationManager.requestAlwaysAuthorization()
            break
        case CQZLocationManagerRequest.WhenInUseAutorization:
            locationManager.requestWhenInUseAuthorization()
            break
        }
    }
    
    public func startUpdatingLocation(){
        locationManager.startUpdatingLocation()
    }
    
    public func stopUpdatingLocation(){
        locationManager.stopUpdatingLocation()
    }
    
    //MARK: - private properties
    private let locationManager = CLLocationManager()
    
    //MARK: - override methods
    @objc private override init(){
        super.init()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.distanceFilter = 15
    }
    
}

//MARK: - CLLocationManagerDelegate
extension CQZLocationManager:CLLocationManagerDelegate {
    public func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        if let location = locations.last {
            currentLocation = location
            delegate?.didUpdateLocation?(location)
        }
    }
    
    public func locationManager(manager: CLLocationManager,
        didChangeAuthorizationStatus status: CLAuthorizationStatus) {
            delegate?.didChangeAuthorizationStatus?(status)
    }
}<commit_msg>actualizada configuración en background y mejora en el performance de la distancia y batería.<commit_after>//
//  CQZLocationManager.swift
//  CQZLocationManager
//
//  Created by <NAME> on 12/28/15.
//  Copyright © 2015 ecorenetworks. All rights reserved.
//

import UIKit
import CoreLocation

@objc public protocol CQZLocationManagerDelegate:NSObjectProtocol {
    optional func didUpdateLocation(location:CLLocation)
    optional func didChangeAuthorizationStatus(status:CLAuthorizationStatus)
}

public class CQZLocationManager: NSObject {
    //MARK: - Singleton
    public static let sharedLocationManager = CQZLocationManager()
    
    //MARK: - public properties
    public var currentLocation:CLLocation = CLLocation()
    weak public var delegate:CQZLocationManagerDelegate?
    
    //MARK: - public methods
    public func requestAutorization (type type:CQZLocationManagerRequest){
        switch type {
        case CQZLocationManagerRequest.AlwaysAuthorization:
            locationManager.requestAlwaysAuthorization()
            break
        case CQZLocationManagerRequest.WhenInUseAutorization:
            locationManager.requestWhenInUseAuthorization()
            break
        }
    }
    
    public func startUpdatingLocation(){
        locationManager.startUpdatingLocation()
    }
    
    public func stopUpdatingLocation(){
        locationManager.stopUpdatingLocation()
    }
    
    public func allowsBackground(allow:Bool) {
        locationManager.allowsBackgroundLocationUpdates = allow
    }
    
    //MARK: - private properties
    private let locationManager = CLLocationManager()
    
    //MARK: - override methods
    @objc private override init(){
        super.init()
        locationManager.delegate = self
        // Set an accuracy level. The higher, the better for energy.
        locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
        // Enable automatic pausing
        locationManager.pausesLocationUpdatesAutomatically = true
        // Specify the type of activity your app is currently performing
        locationManager.activityType = CLActivityType.OtherNavigation
        // Enable background location updates
        locationManager.allowsBackgroundLocationUpdates = true
        // Start location updates
        locationManager.startUpdatingLocation()
    }
    
}

//MARK: - CLLocationManagerDelegate
extension CQZLocationManager:CLLocationManagerDelegate {
    public func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        
        if let location = locations.last {
            currentLocation = location
            delegate?.didUpdateLocation?(location)
        }
        
    }
    
    public func locationManager(manager: CLLocationManager,
        didChangeAuthorizationStatus status: CLAuthorizationStatus) {
            delegate?.didChangeAuthorizationStatus?(status)
    }
}
{'fraction_non_alphanumeric': 0.06556420233463035, 'fraction_numerical': 0.004280155642023347, 'mean_word_length': 3.0640316205533598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '670971', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1279, 'n_words': 301}