I'm new to OS X development, but I have some experience on iOS.
I want to get current location on OS X. I created super simple project, basicaly it's a blank project with core location code added. I use Swift language for development here.
Here is AppDelegate file:
import Cocoa
import CoreLocation
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
if CLLocationManager.authorizationStatus().rawValue == 1 || CLLocationManager.authorizationStatus().rawValue == 2 {
return
}
print(CLLocationManager.authorizationStatus().rawValue)// log: 0
if CLLocationManager.locationServicesEnabled() {
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.startUpdatingLocation()
print("ok") //log: ok
}
}
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
print("\(newLocation) \(oldLocation)")
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
print(locations)
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
print(status)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print(error)
}
}
As you can see, all is pretty obvious here.
CLLocationManager.authorizationStatus is always returns me 0, (e.g. NotDetermined).
I'm expecting to see some iOS like promt to a user, but I don't see it. And I don't recive any location update. No one of this delegate methods are called. I don't understand where I made a mistake, I read Location and Maps Programming Guide and I think I made all steps like in the docs.
Hope somebody could help me with this.