unable to obtain latitude and longitude values of current location in swift 4 for macos app instead I am receiving an error message in the console
"The connection to service named com.apple.locationd.desktop.synchronous was invalidated." UserInfo={NSDebugDescription=The connection to service named com.apple.locationd.desktop.synchronous was invalidated.}
Registration timer expired, but client is still registering!
class ViewController: NSViewController, CLLocationManagerDelegate
{
let locationManager = CLLocationManager()
}
override func viewDidLoad(){
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
print (locationManager.location?.coordinate.latitude ?? 0);
print (locationManager.location?.coordinate.longitude ?? 0);
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print (locationManager.location?.coordinate.latitude ?? 0);
print (locationManager.location?.coordinate.longitude ?? 0);
}
i aslo enabled privacy checks in info.plist
instead of getting the coordinates values in the console I am getting the error message as above. location services enabled on the mac. what's wrong in the code?
This error message means that the application has not been granted permission to obtain the user's location. To fix this you need to ensure that the application is properly "sandboxed" and that the location is enabled. You can do this in Xcode with the following steps:
Now the next time you run your application, it will ask they user to allow it to use the current location. Assuming they answer in the affirmative, you should no longer see the error but instead should see the current position highlighted on the map.