2

I am with Xcode beta 2 and trying to get user location with OS X app, however it is not even asks user permission. here is what I did until now.

...
import CoreLocation

class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate  {

    var locManager : CLLocationManager = CLLocationManager()

    func applicationDidFinishLaunching(aNotification: NSNotification?) {
        locManager.delegate = self
        locManager.desiredAccuracy = kCLLocationAccuracyBest
        locManager.startUpdatingLocation()
    }

    func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
        //doSomething.
    }

}

nothing happens. I looked other questions and try all suggested solutions from answers but did not work. Tried with Objective-C, all fine. Am I missing something here?

Location Service enabled on preferences of the computer. Also "NSLocationUsageDescription" is in info.plist. NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription for 10.10 and later, I am working on 10.9.

Information Property List Key Reference

modusCell
  • 13,151
  • 9
  • 53
  • 80
  • possible duplicate of [Implement CLLocationManagerDelegate methods in Swift](http://stackoverflow.com/questions/24050633/implement-cllocationmanagerdelegate-methods-in-swift) – David Berry Jun 30 '14 at 22:50
  • 1
    That one is IOS, both are not excatly same. – modusCell Jun 30 '14 at 22:54
  • In iOS 8 you have to make a call to request permission and you have to set reasons keys in your info.plist. See [this answer](http://stackoverflow.com/a/24064860/1693173) – progrmr Jul 01 '14 at 01:11
  • I am asking about OS X app however I tried that reason keys in info.plist as well. – modusCell Jul 01 '14 at 01:15

1 Answers1

3

There were no problem code wise, just noticed it is App Sandbox entitlement problem. Once I have checked Location under App Data it worked right away.

enter image description here

modusCell
  • 13,151
  • 9
  • 53
  • 80