【发布时间】:2019-02-17 03:56:12
【问题描述】:
无法在 swift 4 for macos 应用程序中获取当前位置的纬度和经度值,而是在控制台中收到错误消息
“与名为 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 上启用了定位服务。代码有什么问题?
【问题讨论】:
-
打开功能下的位置复选框按钮。