简体   繁体   中英

IOS __connection_block_invoke_2 Swift 2.0 xCode 7.1 El Capitan 10.1

Running Xcode 7.1 on IOS 9.1 on a MBR with El Capitan 10.1. Wrote this simple piece of code that appears run but then doesn't update it would seem and noted this error message; is a silent crash?

"error in __connection_block_invoke_2: Connection interrupted"

Unclear how I can move forward with this? CLLocation does't appear to be updating itself after initially getting a correct value of sorts. Is it related to the above message?

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.
}
}

Doesn't seem to update my location if I walk around with my iPad?

Wrote a comment; double checked and found my target was 8.1; running on an iPad with 9.1. Changed it and now it works!!

Still getting that odd error message; but doesn't seem to stop it working correctly!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM