在装有 El Capitan 10.1 的 MBR 上的 IOS 9.1 上运行 Xcode 7.1。编写了这段看似运行但随后并未更新的简单代码,并注意到了此错误消息;是无声的崩溃吗?
"error in __connection_block_invoke_2: Connection interrupted"
不清楚我该如何推进?在最初获得正确的排序值后,CLLocation 似乎没有 self 更新。是否与上述消息有关?
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var Latitude: UILabel!
@IBOutlet weak var Longitude: UILabel!
@IBOutlet weak var HorizontalAccuracy: UILabel!
@IBOutlet weak var CurrentAlltitude: UILabel!
@IBOutlet weak var VerticalAccuracy: UILabel!
@IBOutlet weak var Distance: UILabel!
var locationManager: CLLocationManager = CLLocationManager()
var startLocation: CLLocation!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
startLocation = nil
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let latestLocation: AnyObject = locations[locations.count - 1]
Latitude.text = String(format: "%.6f",
latestLocation.coordinate.latitude)
Longitude.text = String(format: "%.6f",
latestLocation.coordinate.longitude)
HorizontalAccuracy.text = String(format: "%.4f",
latestLocation.horizontalAccuracy)
CurrentAlltitude.text = String(format: "%.4f",
latestLocation.altitude)
VerticalAccuracy.text = String(format: "%.4f",
latestLocation.verticalAccuracy)
if startLocation == nil {
startLocation = latestLocation as! CLLocation
}
let distanceBetween: CLLocationDistance =
latestLocation.distanceFromLocation(startLocation)
Distance.text = String(format: "%.2f", distanceBetween)
}
func locationManager(manager: CLLocationManager,
didFailWithError error: NSError) {
}
@IBAction func ResetDistance(sender: AnyObject) {
startLocation = nil
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
如果我带着 iPad 走来走去,似乎不会更新我的位置?
最佳答案
发表评论;仔细检查,发现我的目标是 8.1;在装有 9.1 的 iPad 上运行。更改它,现在可以使用了!!
仍然收到奇怪的错误信息;但似乎并没有阻止它正常工作!!
关于IOS __connection_block_invoke_2 Swift 2.0 xCode 7.1 El Capitan 10.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33969377/