位置服务在我的macOS应用程序中不起作用,尽管我已启用它 以下是我的快速代码:
@IBAction func locateMe(_ sender: Any) {
locationManager.delegate = self
if #available(OSX 10.14, *) {
locationManager.startUpdatingLocation()
}
else {
// Fallback on earlier versions
}
if CLLocationManager.locationServicesEnabled() {
print("enabled")
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
else{
print("Disabled")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("error:: \(error.localizedDescription)")
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
print("locations = \(locValue.latitude) \(locValue.longitude)")
// locationManager.stopUpdatingLocation();
}