Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - CLLocationManager not asking for user permission

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

like image 425
modus Avatar asked Dec 12 '25 10:12

modus


1 Answers

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

like image 134
modus Avatar answered Dec 14 '25 08:12

modus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!