iOS didUpdateLocations抛出错误iOS 8.0 Swift

时间:2014-08-30 22:55:25

标签: swift cllocationmanager ios8

不确定是什么问题。我对swift和iOS8很新。但总的来说,我对iOS7中的CLLocationManager没有任何问题。我已经把尽可能多的警示和检查和诽谤,但我一直收到这个错误。请帮忙!

因此,在按钮触摸操作上,我启动了这样的位置管理器,以及imagepicker相机 -

//Start the location manager
        self.captureLocationManager?.requestWhenInUseAuthorization()
        self.captureLocationManager?.delegate = self
        self.captureLocationManager?.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        self.captureLocationManager?.startUpdatingLocation()
        self.captureLocationManager?.distanceFilter = 40
        ....
        {image picker code}

这是我的didUpdateLocations代码

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){
    if locations.count > 0 {
        var latestLocation = locations[locations.count-1] as CLLocation

        if !self.captureGeoCoder.geocoding {
            self.captureGeoCoder.reverseGeocodeLocation(latestLocation, completionHandler: { (placeMarks:[AnyObject]!, error: NSError!) -> Void in
                if error == nil{
                    if placeMarks != nil{

                        self.captureLocationPlaceMark = placeMarks[0] as CLPlacemark
                        println(self.objMomentModel.captureLocationPlaceMark.name)
                        self.captureLocationManager?.stopUpdatingLocation()
                        self.captureLocationManager = nil
                    }
                    else{
                        println("0 placemarks!")
                    }
                }
                else{
                    println("Oops, there was an error in reverseGeoCodeLocation!")
                }


            })
        }
    }
}

但是我的代码在

处解决了
self.captureLocationPlaceMark = placeMarks[0] as CLPlacemark

有一些奇怪的错误,如:

(lldb) 

3 个答案:

答案 0 :(得分:0)

抱歉,这似乎是一个范围问题。

var captureLocationManager = CLLocationManager()
var capturePlaceMark = CLPlacemark()
var captureLocation = CLLocation()

将所有核心变量作为属性有助于didUpdateLocation,didFinishPickingImage和实际IBAction方法之间的值的范围和传输。

感谢您的投入。

答案 1 :(得分:0)

我看到了类似的错误,因为

locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]!)

有时会向地点发送nil。这意味着你的行:

self.captureLocationPlaceMark = placeMarks[0] as CLPlacemark

会抛出一个异常强制打开可选项。有两个修复 - 使用可选的未包装位置声明委托方法,或在检查位置之前检查nil。

答案 2 :(得分:0)

cllocationmanager方法在从iOS升级后出现错误,因为方法发生了变化。 也许如果您使用提供以下内容的相同解决方案:

https://stackoverflow.com/a/25699474/4133150