iOS 11.3,Watch OS 4.3:获取用户在watchOS 4.3中的当前位置?

时间:2018-05-02 05:45:57

标签: ios swift core-location watch-os-4

我在swift中试过这个

How to get the current location in watchOS 2?

但它没有用 这是我在WKInterfaceController

中的代码
override func awake(withContext context: Any?) {
    super.awake(withContext: context)
    self.setupLocation()
}

extension InterfaceController: CLLocationManagerDelegate {

    func setupLocation() {
        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.requestWhenInUseAuthorization()
        self.locationManager.startUpdatingLocation()
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard let currentLocation = locations.first else { return }
        self.currentLocation = currentLocation
        let location = "lat: \(self.currentLocation.coordinate.latitude)\nlong: \(self.currentLocation.coordinate.longitude)"
        self.locationLabel.setText(location)
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("LOCATION MANAGER DID FAIL ERROR : \(error)")
    }
}

我已经在 WatchExtension 主要应用 info.plist中添加了权限。

它仍然没有要求许可警报。 我错过了什么???? :(

0 个答案:

没有答案