How to get user location ? [macOS]

I am trying to get the user's current location using the following code, but it doesn't work. I have added both

NSLocationWhenInUseUsageDescription
key and
NSLocationAlwaysUsageDescription
key to my
Info.plist
file. Below is the code
var locationManager = CLLocationManager();

override func viewDidLoad() {
        super.viewDidLoad()
        startReceivingLocationChanges();
    
        /
    }

    func startReceivingLocationChanges() {
        let authorizationStatus = CLLocationManager.authorizationStatus()
            if authorizationStatus != .authorizedAlways {
                /
                print("not authorized");
                return
            }
        /
        if !CLLocationManager.locationServicesEnabled() {
            /
           /
            print("not enabled");
            return
        }
        /
        locationManager = CLLocationManager();
        locationManager?.delegate = self
        locationManager?.desiredAccuracy = kCLLocationAccuracyHundredMeters
        locationManager?.distanceFilter = 100.0  /
     
        locationManager?.startUpdatingLocation()
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let lastLocation = locations.last!
        print(lastLocation)
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print(error);
    }

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        print("yolo");
    }

Also i am not able to use

locationManager.requestAlwaysAuthorization()

i Get an error saying it is unavailable.

i have read through the apple documents and above is the code that apple suggests. What am i missing here ? Any kind of help is really appreciated. Thanks

Did you ever figure this out?


It sounds like I get a similar error when I try to use locationManager.request...Authorization; it doesn't seem to matter if I use always for when using app.


I have set the key pairs for Privacy - Location.

How to get user location ? [macOS]
 
 
Q