gpt4 book ai didi

ios - 启动 IOS map GPS 导航并返回应用程序后应用程序崩溃

转载 作者:行者123 更新时间:2023-11-30 13:30:10 26 4
gpt4 key购买 nike

我尝试使用以下代码启动 GPS 导航,但我的应用程序崩溃了,而且它没有告诉我任何信息。 map 应用程序和逐向导航启动正常,启动后运行良好,但我的应用程序崩溃了。

已更新

抱歉,让我添加更多上下文。导航和 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 已损坏。我的代码没问题。我创建了另一个 View Controller ,添加了所有小部件并连接了我的代码,一切正常。

关于ios - 启动 IOS map GPS 导航并返回应用程序后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36656594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com