Ich versuche, die GPS-Navigation mit den folgenden Codes zu starten, aber meine App stürzt ab und es sagt mir nichts. Die Karten-App und Turn-by-Turn-Navigation startet gut und läuft gut, nachdem es initiiert wurde, aber meine App abstürzt.App stürzt ab, nachdem IOS Karte GPS Navigation gestartet und zur App
AKTUALISIERT
Sorry, lassen Sie mich mehr Kontext hinzufügen. Nachdem die Navigation und GPS gestartet sind und ich versuche, zu meiner App zurückzukehren, stürzt die App ab. Hier ist der vollständige Code.
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")
}
}
}
Was sind die Details des Absturzes? – Paulw11
Es sagt nicht. Das frustriert mich. –