定位服务在我的macOS应用程序中不起作用

时间:2019-06-18 09:08:48

标签: swift xcode macos cocoa core-location

位置服务在我的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();
    }

这里禁用打印 但是我已经在系统偏好设置中启用了位置,如下图所示 enter image description here

0 个答案:

没有答案