⚠️ Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 1.)
为什么会出现此错误?它工作了很长时间,突然我开始收到此错误。我读过其他人的解决方案,它们只是重新启动他们的设备和Xcode并进行更新,到目前为止,所有这些都无济于事。
import Foundation
import CoreLocation
import UIKit
class LocationDelegate: NSObject, CLLocationManagerDelegate {
var headingCallback: ((CLLocationDirection) -> ())? = nil
var locationCallback: ((CLLocation) -> ())? = nil
var bearing = 0.0
var speed = 0.0
var speedCallBack: ((CLLocation) -> ())? = nil
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let currentLocation = locations.last else { return }
locationCallback?(currentLocation)
speedCallBack?(currentLocation)
var location: CLLocation = locations.last!
speed = location.speed
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
headingCallback?(newHeading.trueHeading)
bearing = newHeading.trueHeading
}
func returnMPHSpeed() -> Double {
//print ("speed : ", speed)
return speed * 2.23602484472
}
func returnKMHSpeed() -> Double {
return speed
}
func returnHeading() -> Int {
return Int(bearing)
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("⚠️ Error while updating location " + error.localizedDescription)
}
}