【发布时间】:2014-08-30 22:55:24
【问题描述】:
不确定是什么问题。我对 swift 和 iOS8 非常陌生。但总的来说,我对 iOS7 中的 CLLocationManager 没有任何问题。我已经提出了尽可能多的警告 ifs 和 check 和 nils,但我不断收到这个错误。请帮忙!
因此,在按钮触摸操作中,我像这样启动位置管理器,以及图像选择器相机 -
//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)
【问题讨论】:
-
这可能无关紧要,但也可能无关...无论如何,这行肯定是错误的:
if error == nil- 你不应该检查error,除非placeMarks为nil。试着去掉那部分情况,看看情况是否有所改善。如果他们不这样做,删除它仍然是正确的。 -
为什么会出错?如果有错误,我不应该停止继续处理其余代码吗?
-
错误是什么?您只输入 lldb 提示符。
-
是的,我试过了,这不是错误。看起来问题是由于变量范围造成的。我将所有这些都作为 Controller 类的属性,它起作用了。 var captureLocationManager = CLLocationManager() var capturePlaceMark = CLPlacemark() var captureLocation = CLLocation()
标签: swift cllocationmanager ios8