Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created June 6, 2014 05:57
Show Gist options
  • Save jhurliman/45bcdfbe2240e72c8bc7 to your computer and use it in GitHub Desktop.
Save jhurliman/45bcdfbe2240e72c8bc7 to your computer and use it in GitHub Desktop.
import UIKit
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var window: UIWindow?
let locationManager: CLLocationManager = CLLocationManager()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
locationManager.delegate = self
return true
}
deinit {
locationManager.delegate = nil
}
func applicationDidBecomeActive(application: UIApplication) {
locationManager.requestAlwaysAuthorization()
locationManager.startMonitoringVisits()
}
func locationManager(manager: CLLocationManager!, didVisit visit: CLVisit!) {
NSLog("didVisit \(visit)")
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
NSLog("[ERROR] \(error)")
}
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
var str: String
switch (status) {
case .NotDetermined: str = "NotDetermined"
case .Restricted: str = "Restricted"
case .Denied: str = "Denied"
case .Authorized: str = "Authorized"
case .AuthorizedWhenInUse: str = "AuthorizedWhenInUse"
}
NSLog("CLAuthorizationStatus: \(str)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment