我已经快速尝试过了
但它不起作用这是我在 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和Main App info.plist 中添加了权限。
它甚至还没有询问权限警报。我错过了什么???:(