无法获取swift 4中macos app的当前位置的纬度和经度值,而是在控制台中收到错误消息
“名为com.apple.locationd.desktop.synchronous的服务连接无效。” UserInfo = {NSDebugDescription =名为com.apple.locationd.desktop.synchronous的服务连接无效。}
注册计时器已过期,但客户端仍在注册!
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);
}
我还在info.plist中启用了隐私检查
而不是在控制台中获取坐标值我得到如上所述的错误消息。在mac上启用了位置服务。代码中有什么问题?
此错误消息表示尚未授予应用程序获取用户位置的权限。要解决此问题,您需要确保应用程序已正确“沙盒化”并且已启用该位置。您可以使用以下步骤在Xcode中执行此操作:
现在,下次运行应用程序时,它会要求用户允许它使用当前位置。假设他们回答是肯定的,你应该不再看到错误,而是应该看到地图上突出显示的当前位置。