CLLocationManager忽略stopUpdatingLocation

Tom*_*you 1 objective-c core-location cllocationmanager ios swift

我正在呼叫startUpdatingLocation()一个CLLocationManager,并且在didUpdateLocations我正在调用的方法中,stopUpdatingLocation()当精度小于100米时,就像这样:

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    var lastLocation: CLLocation = locations.last! as! CLLocation
    var accuracy = lastLocation.horizontalAccuracy

    if (accuracy < 100) {
        locationCoordinate = lastLocation.coordinate
        locationManager.stopUpdatingLocation()
        getData()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,除非我设置为to ,否则didUpdateLocations调用后仍然会调用该方法一两次.显然,这也多次调用我的方法,这是我不想要的.如何在不设置等于的情况下停止?stopUpdatingLocations()locationManagernilgetData()locationManagernil

小智 6

我也面临类似的问题.我通过将CLLocationManagerDelegate设置为nil来解决它