IOS __connection_block_invoke_2 Swift 2.0 xCode 7.1 El Capitan 10.1

标签 ios swift cllocation

在装有 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/

相关文章:

swift - 如何使用 SwiftUI 对可隐藏 View 进行动画处理?

ios - 如何以编程方式快速将 subview 添加到自定义 View

ios - 如何获取 NSFetchedResultsController Swift 部分中的对象数

ios - iOS Obj-C从CLLocation提取纬度

ios - 如何使用 NSKeyedArchiver 存储 CLLocation 对象?

ios - 如何在ios中关闭应用程序时显示警报

ios - 从日历中检索带有标识符的事件时应用程序崩溃

ios - 如何在 iOS 设备上测试 iAd?我在哪里可以看到设置 iAd 网络选项?

ios - .notDetermined 等待用户的响应

ios - 无法推断出 RxDataSources `Generic parameter ' Self'