<commit_before>//
//  GeoManager.swift
//  WikiLocation
//
//  Created by <NAME> on 29.06.14.
//  Copyright (c) 2014 enterprise. All rights reserved.
//

import Foundation
import CoreLocation

class GeoManager : NSObject, CLLocationManagerDelegate {
    
    //#pragma mark - Properties
    var locationManager:CLLocationManager = CLLocationManager()
    var location:CLLocation?
    var locationAuthorized = false
    
    class var sharedInstance: GeoManager {
    struct SharedInstance {
        static let instance = GeoManager()
        }
        return SharedInstance.instance
    }
    
    //#pragma mark - Init & deinit
    init() {
        super.init()
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground:",
            name: UIApplicationDidEnterBackgroundNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground:",
            name: UIApplicationWillTerminateNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterForeground:",
            name: UIApplicationWillEnterForegroundNotification, object: nil)
        
    }
    
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    //#pragma mark - Start & Stop
    func start() {
        
        self.locationManager.requestWhenInUseAuthorization()
        
        if self.isLocatingAllowed() {
            self.locationAuthorized = true
            self.locationManager.delegate = self
            self.locationManager.desiredAccuracy = 300  // Meter
            self.locationManager.startUpdatingLocation()
        }
    }
    
    func stop() {
        self.locationManager.stopUpdatingLocation()
        self.locationManager.delegate = nil
    }
    
    func isLocatingAllowed() -> Bool {
        var allowed = false

        if CLLocationManager.locationServicesEnabled() == true {
            allowed = true
        }
        if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse {
            allowed = true
        } else {
            allowed = false
        }
        
        return allowed
    }
    
    //#pragma mark - CLLocationManagerDelegate
    func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!) {
        
        if locations.count > 0 && self.location == nil {
            self.location = locations[0] as? CLLocation
            self.locationManager.stopUpdatingLocation()
        }
    }
    
    func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
        
    }
    
    func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        if (!self.locationAuthorized && status == .AuthorizedWhenInUse) {
            // Location service was not enabled before - now start the location service again
            self.start()
        }
    }
    
    //#pragma mark - Notifications
    func didEnterBackground(notification:AnyObject) {
        self.stop()
        // also destroy the latest location - we refresh when coming into foreground
        self.location = nil
    }
    
    func didEnterForeground(notification:AnyObject) {
        self.start()
    }
}<commit_msg>Update GeoManager.swift<commit_after>//
//  GeoManager.swift
//  WikiLocation
//
//  Created by <NAME> on 29.06.14.
//  Copyright (c) 2014 enterprise. All rights reserved.
//

import Foundation
import CoreLocation

public class GeoManager : NSObject, CLLocationManagerDelegate {
    
    //#pragma mark - Properties
    var locationManager:CLLocationManager = CLLocationManager()
    private(set)  var location:CLLocation?
    var locationAuthorized = false
    
    public class var sharedInstance: GeoManager {
        struct SharedInstance {
            static let instance = GeoManager()
        }
        return SharedInstance.instance
    }
    
    //#pragma mark - Init & deinit
    init() {
        super.init()
        
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground:",
            name: UIApplicationDidEnterBackgroundNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground:",
            name: UIApplicationWillTerminateNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterForeground:",
            name: UIApplicationWillEnterForegroundNotification, object: nil)
        
    }
    
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    //#pragma mark - Start & Stop
    public func start() {
        self.locationManager.requestWhenInUseAuthorization()
        
        if self.isLocatingAllowed() {
            self.locationAuthorized = true
            self.locationManager.delegate = self
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest  // Meter
            self.locationManager.startUpdatingLocation()
        }
    }
    
    public func stop() {
        self.locationManager.stopUpdatingLocation()
        self.locationManager.delegate = nil
    }
    
    func isLocatingAllowed() -> Bool {
        var allowed = false
        
        if CLLocationManager.locationServicesEnabled() == true {
            allowed = true
        }
        if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse {
            allowed = true
        } else {
            allowed = false
        }
        
        return allowed
    }
    
    //#pragma mark - CLLocationManagerDelegate
    public func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
            if locations.count > 0 && self.location == nil {
            self.location = locations[0] as? CLLocation
            self.locationManager.stopUpdatingLocation()
        }
    }
    
    public func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
        
    }
    
    public func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        if (!self.locationAuthorized && status == .AuthorizedWhenInUse) {
            // Location service was not enabled before - now start the location service again
            self.start()
        }
    }
    
    //#pragma mark - Notifications
    func didEnterBackground(notification:AnyObject) {
        self.stop()
        // also destroy the latest location - we refresh when coming into foreground
        self.location = nil
    }
    
    func didEnterForeground(notification:AnyObject) {
        self.start()
    }
}
{'fraction_non_alphanumeric': 0.08327126471026366, 'fraction_numerical': 0.004022046774914345, 'mean_word_length': 2.3536463536463534, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2731244', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1680, 'n_words': 385}