允许获取用户位置通知不';我不能在ios 8上露面

允许获取用户位置通知不';我不能在ios 8上露面,ios,swift,mapkit,core-location,Ios,Swift,Mapkit,Core Location,我正在尝试写入从用户位置到目标点的路由 我添加了info.plist这些行 这是我写路线的代码: class ItinerarioVC: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate { @IBOutlet var steps: UITextView! @IBOutlet var distanceLabel: UILabel! @IBOutlet var destinationLabel: UILabel! @IB

我正在尝试写入从用户位置到目标点的路由

我添加了
info.plist
这些行

这是我写路线的代码:

class ItinerarioVC: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet var steps: UITextView!
@IBOutlet var distanceLabel: UILabel!
@IBOutlet var destinationLabel: UILabel!
@IBOutlet var theMapView: MKMapView!

let locationManager = CLLocationManager()
var annotationTitle: NSString!
var annotationSubheading:Int!

var routeDetails: MKRoute!
var allSteps: NSString!
var destinationCoordinate: CLLocationCoordinate2D!

override func viewDidLoad() {
    super.viewDidLoad()
  }

override func viewWillAppear(animated: Bool) {

    //setup our location manager
    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.requestAlwaysAuthorization()
    self.locationManager.startUpdatingLocation()

    //setup our map view
    theMapView.showsUserLocation = true

    var destinationPlacemark:MKPlacemark = MKPlacemark(coordinate: destinationCoordinate, addressDictionary: nil)
    var source:MKMapItem = MKMapItem.mapItemForCurrentLocation()

    var destination:MKMapItem = MKMapItem(placemark: destinationPlacemark)
    var directionRequest:MKDirectionsRequest = MKDirectionsRequest()

    directionRequest.setSource(source)
    directionRequest.setDestination(destination)
    directionRequest.transportType = MKDirectionsTransportType.Automobile
    directionRequest.requestsAlternateRoutes = true

    var directions:MKDirections = MKDirections(request: directionRequest)
    directions.calculateDirectionsWithCompletionHandler({
        (response: MKDirectionsResponse!, error: NSError?) in
        if error != nil{
            println("Error for getting direction: \(error)")
        }
        if response != nil{

            // find the best way
            var temp:MKRoute = response.routes.first as MKRoute
            var min = response.routes.first?.distance
            for (var i=1; i < response.routes.count; i++)
            {
                if response.routes[i].distance < min
                {min = response.routes[i].distance
                    temp = response.routes[i] as MKRoute}
            }
            self.routeDetails = temp
            self.theMapView.addOverlay(self.routeDetails.polyline)
            if (self.annotationSubheading != 0)
            {
                if self.annotationSubheading == 20
                {
                    self.destinationLabel.text = eventPub.title as String
                }
                else
                {
                    self.destinationLabel.text = companyWithServicePub.name as String
                }
                self.destinationLabel.adjustsFontSizeToFitWidth = true
            }

            self.distanceLabel.text = NSString(format:"%0.1f KM", self.routeDetails.distance/1000)

            setRegionToFit(self.theMapView)
            self.allSteps = ""

            for (var i = 0; i < self.routeDetails.steps.count; i++)
            {
                var step:MKRouteStep = self.routeDetails.steps[i] as MKRouteStep;
                var newStep:NSString = step.instructions
                self.allSteps = self.allSteps.stringByAppendingString( "\(i+1). ")
                self.allSteps = self.allSteps.stringByAppendingString(newStep)
                self.allSteps = self.allSteps.stringByAppendingString("\n\n");
                self.steps.text = self.allSteps;
            }
        }
        else{
            println("No response")
        }
        println(error?.description)
    })

    // show destination on map

    var destannotation = CustomPointAnnotation()
    destannotation.title = annotationTitle
    destannotation.coordinate = destinationCoordinate
    destannotation.subheading = annotationSubheading
    self.theMapView.addAnnotation(destannotation)
 }

func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
    if overlay is MKPolyline {
        var polylineRenderer = MKPolylineRenderer(overlay: overlay)
        polylineRenderer.strokeColor = UIColor.blueColor()
        polylineRenderer.lineWidth = 4
        return polylineRenderer
        }
    return nil
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: { (placemarks,error) -> Void in
        if (error != nil) {
            println("Error to get user location: " + error.localizedDescription)
            return
        }

        if placemarks.count > 0 {
            let pm = placemarks[0] as CLPlacemark

        }
        else {println("Error with data")}
    })
}


func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
    println("Error: with user location" + error.localizedDescription)
    self.locationManager.stopUpdatingLocation()
}
}
有人能告诉我我的代码出了什么问题吗? 我想知道,即使第一次尝试没有成功,我如何让我的应用程序继续查找用户位置


提前谢谢。

您是否尝试过重置模拟器?或者卸载并重建你的应用程序?我正在iphone上运行此操作,而不是在模拟器上运行。尝试删除应用程序并重新构建。我尝试过,但仍然没有显示。删除行
requestwhenUseAuthorization
requestAlwaysAuthorization
!只用一个!
Error for getting direction: Optional(Error Domain=MKLocationErrorDomain Code=0 "The operation couldn’t be completed. (MKLocationErrorDomain error 0.)"     UserInfo=0x17086ee40 {NSLocalizedRecoverySuggestion=Active localization to allow (null) to determine your location})
No response
Optional("Error Domain=MKLocationErrorDomain Code=0 \"The operation couldn’t be completed. (MKLocationErrorDomain error 0.)\" UserInfo=0x17086ee40 {NSLocalizedRecoverySuggestion=Active localization to allow (null) to determine your location}")
Error: with user locationThe operation couldn’t be completed. (kCLErrorDomain error 1.)