Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
启动IOS地图GPS导航并返回应用程序后,应用程序崩溃_Ios_Swift_Dictionary_Gps_Mapkit - Fatal编程技术网

启动IOS地图GPS导航并返回应用程序后,应用程序崩溃

启动IOS地图GPS导航并返回应用程序后,应用程序崩溃,ios,swift,dictionary,gps,mapkit,Ios,Swift,Dictionary,Gps,Mapkit,我正试图用以下代码启动GPS导航,但我的应用程序崩溃了,它没有告诉我任何事情。地图应用程序和逐轮导航启动正常,启动后运行正常,但我的应用程序崩溃 已更新 抱歉,让我添加更多上下文。导航和GPS启动后,我试图返回我的应用程序,应用程序崩溃。这是完整的代码 import UIKit import MapKit import CoreData class DetailViewController: UIViewController { var pho : Pho? = nil

我正试图用以下代码启动GPS导航,但我的应用程序崩溃了,它没有告诉我任何事情。地图应用程序和逐轮导航启动正常,启动后运行正常,但我的应用程序崩溃

已更新

抱歉,让我添加更多上下文。导航和GPS启动后,我试图返回我的应用程序,应用程序崩溃。这是完整的代码

 import UIKit
import MapKit
import CoreData

class DetailViewController: UIViewController  {

    var pho : Pho? = nil

    @IBOutlet var titleLabel: UILabel!

    @IBOutlet var phoneLabel: UILabel!

    @IBOutlet var addressLabel: UILabel!

    @IBOutlet var zomatoLabel: UILabel!

    @IBOutlet var googleLabel: UILabel!

    @IBOutlet var yelpLabel: UILabel!

    @IBOutlet var mapView: MKMapView!

    @IBOutlet var saveButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.



        // We need just to get the documents folder url
        let documentsUrl =  NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!

        //         now lets get the directory contents (including folders)

//        do {
//            let directoryContents = try NSFileManager.defaultManager().contentsOfDirectoryAtURL(documentsUrl, includingPropertiesForKeys: nil, options: NSDirectoryEnumerationOptions())
//            print(directoryContents)
//            
//            for x in directoryContents {
//                print(x)
//            }
//            
//        } catch let error as NSError {
//            print(error.localizedDescription)
//        }




    }

    override func viewWillAppear(animated: Bool) {

        self.titleLabel.text = self.pho!.name
        self.phoneLabel.text = String(self.pho!.phoneNumber)
        self.addressLabel.text = self.pho!.address

        self.zomatoLabel.text = "\(self.pho!.rating) - \(self.pho!.votes) reviews"

        self.googleLabel.text = "\(self.pho!.gRating)"

        self.yelpLabel.text = "\(self.pho!.yRating) - \(self.pho!.yVotes) reviews"

        let latitudeAnn:CLLocationDegrees = self.pho!.latitude
        let longitudeAnn:CLLocationDegrees = self.pho!.longitude

        let latDelta:CLLocationDegrees = 0.05
        let lonDelta:CLLocationDegrees = 0.05

        let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)

        let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitudeAnn, longitudeAnn)

        let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)

        let annotation = MKPointAnnotation()

        annotation.coordinate = location

        self.mapView.addAnnotation(annotation)

        self.mapView.setRegion(region, animated: true)
        let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

        let context: NSManagedObjectContext = appDel.managedObjectContext

        let request = NSFetchRequest(entityName: "Restaurant")
        //        request.predicate = NSPredicate(format: "latitude = %@", latitude)
        let firstPredicate = NSPredicate(format: "name = %@", "\(self.pho!.name)")
        let secondPredicate = NSPredicate(format: "address = %@", "\(self.pho!.address)")
        request.returnsObjectsAsFaults = false

        request.predicate = NSCompoundPredicate(type: NSCompoundPredicateType.AndPredicateType, subpredicates: [firstPredicate, secondPredicate])

        do {

            let results = try context.executeFetchRequest(request)

            if results.count > 0 {
                print(results)
                self.saveButton.hidden = true

                for result in results as! [NSManagedObject] {


                }
            }
        } catch {
        }
    }


    @IBAction func initDirection(sender: AnyObject) {



                let latitudeAnn:CLLocationDegrees = self.pho!.latitude
                let longitudeAnn:CLLocationDegrees = self.pho!.longitude

                let coordinates:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitudeAnn, longitudeAnn)

                let launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving]
                let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
                let mapItem = MKMapItem(placemark: placemark)

                mapItem.name = "\(self.pho!.name)"

                mapItem.openInMapsWithLaunchOptions(launchOptions)


    }

    @IBAction func savePho(sender: AnyObject) {

        self.saveButton.hidden = true

        let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

        let context: NSManagedObjectContext = appDel.managedObjectContext

        let newRestaurant = NSEntityDescription.insertNewObjectForEntityForName("Restaurant", inManagedObjectContext: context)

        newRestaurant.setValue(self.pho!.latitude, forKey: "latitude")

        newRestaurant.setValue(self.pho!.longitude, forKey: "longitude")

        newRestaurant.setValue(self.pho!.name, forKey: "name")

        newRestaurant.setValue(self.pho!.phoneNumber, forKey: "phone")

        newRestaurant.setValue(self.pho!.address, forKey: "address")

        do {
            try context.save()
        } catch {
            print("There was a problem")
        }
    }

}

所以我发现XML被破坏了。我的密码很好。我创建了另一个视图控制器,添加了所有的小部件,连接了我的代码,一切正常

坠机的细节是什么?没有说。这就是让我沮丧的地方。